On Wed, Mar 9, 2011 at 11:53 AM, eric wong <ewl...@gmail.com> wrote: > But now, I must get the data from certain PATIENT_GROUP. > > What's your best approach to solve this? The objective is the fastest > possible query. > > Thanks. > >
There's an approach with "order by random" mentioned by Richard, there's also another one that is self-explained from this query SELECT * FROM Table LIMIT 1 OFFSET abs(random() % (SELECT Count(*) FROM Table)) in your case this should lead to something like SELECT patient_id FROM TB_Patient WHERE patient_group=$group LIMIT 1 OFFSET abs(random() % (SELECT Count(*) FROM TB_Patient WHERE GroupId=$group) Both approaches should scan the table so slow for large tables by design, but I found the latter being a slightly faster, but I'm not sure whether this is always the case. Max Vlasov _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users