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 […]

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 *!

Duncan Isaksen-Loxton

Educated as a web developer, with over 20 years of internet based work and experience, Duncan is a Google Workspace Certified Collaboration Engineer and a WordPress expert.
Login
Log in below to access your courses.
Log In With Google
Forgot Password
Enter your email address or username and we’ll send you instructions to reset your password.