[thelist] Free SQL Tip
Burhan Khalid
thelist at meidomus.com
Wed Sep 1 01:22:58 CDT 2004
On Tue, 2004-08-31 at 21:50, Joshua Olson wrote:
[ snipped out the <tip> tag, as to not have duplicate tips ]
> Here's a great way to get fields from a table back in random order on SQL
> Server. First, add a new column, call it "rank". Set it to data type
> "uniqueidentifier" and then set its formula to "(newid())".
>
> Then, simply ORDER BY this new columns. Example:
>
> SELECT id, name, eyeColor
> FROM people
> ORDER BY rank
To do the same in MySQL:
SELECT id, name, eyeColor FROM `people` ORDER BY RAND()
You can also limit the results. For example, five random entries:
SELECT id, name, eyeColor FROM `people` ORDER BY RAND() LIMIT 5
I guess RAND() is a MySQL specific function?
More information about the thelist
mailing list