Results 1 to 3 of 3
Thread: Another group by, order by query
May 5, 2003, 12:03 #1
- Join Date
- Oct 2001
- Helston, Cornwall, England
- 0 Post(s)
- 0 Thread(s)
Another group by, order by query
I have a question regarding the use of group by and order by in the same query.
I am trying to return a return a set of random results from a database, order by RAND(), but have them grouped together, by another field.
SELECT * FROM "db" WHERE town LIKE '$town' ORDER BY RAND()
Returns all the results in random order. I now want to group them with by another field.
SELECT * FROM "db" WHERE town LIKE '$town' GROUP BY sleeps ORDER BY RAND()
This works but obviously only returns 1 set of sleeps field, how do I return all entries?
http://www.choosespain.com/newtownpage.php is a basic order by RAND(), but as you'll see I need to Group the random results by the number of persons each property sleeps.
Hope I've explained myself ok.
Thanks in advance