Selecting a Random Row from an SQLite Table

Album Cover: No Code

"Are you woman enough to be my man?"
Pearl Jam / Hail Hail

Posted on May 13, 2008 8:32 PM in Web Development

When I originally presented my version of selecting a random row from a MySQL table, a commenter named Elvard set me straight:

SELECT * FROM table ORDER BY RAND () LIMIT 1;

Tonight, out of pure curiosity, I learned that selecting a random row from an SQLite table isn't much different:

SELECT * FROM table ORDER BY RANDOM() LIMIT 1;

The only key difference being that MySQL supports the RAND() function, whereas SQLite's is called RANDOM().

Comments

No one has added any comments.

Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.

Name:

Email Address:

Website:

Comments:

Check this box if you hate spam.