On Thu, Mar 8, 2012 at 15:02, Igor Tandetnik <itandet...@mvps.org> wrote: > Benoit Mortgat <mort...@gmail.com> wrote: >> * Generate N, random, row numbers between 1 and (SELECT COUNT(*) FROM >> the_table_name). Maybe using remainder operator % and builtin ABS() >> and RANDOM() functions can help (see below) * SELECT FROM the_table >> WHERE rowid IN (those random numbers) > > That is not equivalent. First, duplicate random numbers may be > generated. Second, rowid values are not necessarily sequential. Thus, > you may end up with fewer than N rows.
Oh, I assumed rowids were sequential. If that's not the case, then you're right and my query is bad. Thanks for pointing that out. > You can implement this algorithm in your application's code, if you > are so inclined. Still, what I told is that I use that query only to get a random sample for displaying. I do that from inside the SQLite shell, for vizualization purposes, and as soon as I get approximately N results, this is satisfactory to me. I am not integrating anything into an application. -- Benoit Mortgat _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users