tags:

views:

328

answers:

3

I have an sqlite table with the following schema:

CREATE TABLE foo (bar VARCHAR)

I'm using this table as storage for a list of strings.

How do I select a random row from this table?

+2  A: 

Have a look at Selecting a Random Row from an SQLite Table

SELECT * FROM table ORDER BY RANDOM() LIMIT 1;
astander
Your answer seems to be similar with the one provided by Svetlozar. So I have the same question for you.
Alex_coder
+1  A: 
SELECT   bar
FROM     foo
ORDER BY Random()
LIMIT    1
Svetlozar Angelov
Since it will select the whole table content first, wouldn't this be very time-consuming for large tables?
Alex_coder
Can't you just limit the scope using "WHERE" condition(s)?
jldupont