Re: [sqlite] Re: selecting a random record from a table

2007-01-26 Thread Nicolas Williams
On Fri, Jan 26, 2007 at 09:16:41AM -0700, Dennis Cote wrote: > The offset mechanism proposed by Igor earlier is far more efficient as > long as you know the size of the table. You can always get the size from > a count query, which also requires a table scan, but even that is less > expensive

Re: [sqlite] Re: selecting a random record from a table

2007-01-26 Thread Dennis Cote
Igor Tandetnik wrote: P Kishor <[EMAIL PROTECTED]> wrote: On 1/25/07, Artem Yankovskiy select * from table1 order by random(id) limit 1 Yes, very nice, thank you. I am not familiar with the "ORDER BY random(col)" idiom. How does this work? (It does work alright). random(anything) produces

[sqlite] Re: selecting a random record from a table

2007-01-25 Thread Igor Tandetnik
P Kishor <[EMAIL PROTECTED]> wrote: On 1/25/07, Artem Yankovskiy wrote: select * from table1 order by random(id) limit 1 Yes, very nice, thank you. I am not familiar with the "ORDER BY random(col)" idiom. How does this work? (It does work alright). random(anything) produces a random

[sqlite] Re: selecting a random record from a table

2007-01-25 Thread Igor Tandetnik
P Kishor <[EMAIL PROTECTED]> wrote: 1. given a non-sequential id, select all the ids 2. grab a random id 3. select the row with that id. is there a better way of accomplishing this, one that requires a single round-trip to the db? If you can somehow keep track of the number of rows (N) in the