Pull Random Records, But No Duplicates
Simple question.
I've got a query that pulls four random records, like so:
<CFQUERY NAME="my_query" DATASOURCE="#request.my_datasource#" DBTYPE=ODBC MAXROWS=4>
SELECT p.first_name, p.last_name
FROM people p, offices o, buildings b, cities c
WHERE p.people_id = o.people_id AND o.building_id = b.building_id AND b.city_id = c.city_id AND c.city_id = 12
ORDER BY newid()
</CFQUERY>
Problem is, duplicates can occur if a the "offices" table has multiple instances of the same person, or "people_id".
"distinct" is out of the question, as it would have to be added to the SELECT list.
So, how can one generate random records, when "distinct" is not an option? I feel I got it to work with some GROUP BY trickery...
...but I'm not confident that's the best solution.
