Does anyone know a better way to pull a random row based on the same ID from another table.
The following sql statement works perfectly. Its just a little taxing on the mysql server.
SELECT e.* , SUBSTRING_INDEX(MIN(CONCAT_WS('|', RAND(), p.image)), '|', -1) AS randImage
FROM Events AS e INNER JOIN Photos AS p USING(cid)
GROUP BY e.cid ORDER BY RAND() LIMIT 20
Example Output:
Album 01 - Display Random Picture from Album 01
Album 02 - Display Random Picture from Album 02
Sample DBs:
CID AlbumName
PID CID ImagePath