I have a table of records each of which belongs to a collection. I want to list the collections and with each collection have a random record from that collection.
Currently I have a count but I would like to also return the random id from the records table. I cannot get my head around it. Any suggestions?
Current query.
select
collections.name,collections.id, count(records.id) as count
from
collections, records
where
records.collection_id = collections.id
group by
collections.id
order by
collections.name