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 […]
February 5, 2007 7:55 am

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:

This brilliantly selects a row at ‘random’ from the given table. And yes, I know I shouldnt use select *!

Leave a Comment