anu123 Posted January 15, 2009 Share Posted January 15, 2009 Hi I have a query SELECT * FROM table1 AS a WHERE a.user_id NOT IN (SELECT c.user_id FROM table2 AS c) and (a.sentby = ‘S’ or a. sentby =’B’ or a. sentby = ‘R’) This was running fine when the number of users in the site was less, but as the user number increased, the the query is taking too much time to run. Can anyone help me with how to optimize this query so that, the site wont get slow Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/140905-query-optimization/ Share on other sites More sharing options...
fenway Posted January 18, 2009 Share Posted January 18, 2009 Hard to tell without EXPLAIN output. Try this: SELECT * FROM table1 AS a LEFT JOIN table2 AS c USING ( user_id ) WHERE c.user_id IS NULL and (a.sentby = ‘S’ or a. sentby =’B’ or a. sentby = ‘R’) Quote Link to comment https://forums.phpfreaks.com/topic/140905-query-optimization/#findComment-739715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.