Hi. I have a big table in my database (potentially millions of records) and I need to select X random rows (let's say X between 10 and 50) , but I need this query to be as optimal as possible.
The table looks like this: CREATE TABLE sample ( id bigint auto_increment PRIMARY KEY, user_id bigint NOT NULL, screen_name VARCHAR NOT NULL, ... ); I've searched around and I found answers like this: SELECT * FROM sample ORDER BY RAND() limit X. It looks to me that this will fetch the full table, isn't it? I think it would be best to generate 10 or 50 random intengers and do a "select * from sample where rowid in (<random integer list>)". But afaik, rowid concept is missing in H2, so I may opt for using the ID column in my table. Any advice? Thanks in advance. Luigi. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
