Query - Optimized

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Query - Optimized

Post 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.
Post Reply