SQLITE again

Miscellaneous Forums/General Discussion/SQLITE again

Should this work correctly?

SELECT id FROM club ORDER BY RANDOM() LIMIT 2

It appears to be selecting random clubs but the same teams keep cropping up. There are hundreds of teams in the db so I'm not sure why i'm seeing the same clubs all the time. Any ideas?

Don't know about SQLITE but in other dialects you have to take care with the equivalent of RANDOM(). What it does is generate a single random value for the query that is used for all projected rows.

Look at the values to confirm that they are the same for all rows.

Then I guess that SQLITE is returning the rows in whatever order that they have in the table since they have the same RANDOM() value.

See if there is a NewID function or some other function to return a pseudo-random value that varies for each row and for each invocation.

A quick google search reveals this: http://www.mail-archive.com/sqlite-users@...