Page 1 of 1

Query - Optimized

Posted: Thu Apr 14, 2011 12:06 pm
by agriz
Hi,

I have two table involved in this query.

One is questions (now have 20,000 records - It might grow to 1 lakh in future)
Another one is user who attended questions.

Now, I want to get only unattended random questions.
first, I get the maximum id from questions table. then,

Code: Select all

$rand = rand(1,$max_id);
After that, I write

Code: Select all

select * from questions where id not in (subsquery) and id >= $rand
The Not IN part might take more and more ids in future.
>=$rand have chance to bring no result, i think

Please give me some idea to optimize this query if i am wrong.