Random rows in SQL
We recently had to work out how to display a random quote from a table in the database.
Clearly we could have created a random number with CF and then simply retrieved that row or id from the database, but what if the rows didn't have consecutive ID's?
We came up with this solution in SQL:
ORDER BY NEWID()
This brilliantly selects a row at 'random' from the given table. And yes, I know I shouldnt use select *!


There are no comments for this entry.
[Add Comment]