plusnplus Posted March 19, 2010 Share Posted March 19, 2010 Hi, my query is: select distinct cust_id from tabel_sales where item_code !='110' and cust_id not in (select cust_id from table_sales where item_code='110') purpose of the query is to get customer that NOT have item code 110. this query work fine, but take very long time (for 12.000 record plus) Quote Link to comment https://forums.phpfreaks.com/topic/195782-how-to-make-this-query-better/ Share on other sites More sharing options...
plusnplus Posted March 22, 2010 Author Share Posted March 22, 2010 After run few test, the query not run properly. for more info: table_sales record is like: cust_id item_id item_qty abc 100 100 abc 110 100 abc 120 100 abb 100 100 abb 120 100 abb 130 100 aba 110 100 aba 120 100 aba 130 100 Thanks for any help/ idea Quote Link to comment https://forums.phpfreaks.com/topic/195782-how-to-make-this-query-better/#findComment-1029822 Share on other sites More sharing options...
fenway Posted March 22, 2010 Share Posted March 22, 2010 Use a LEFT JOIN... IS NULL. Quote Link to comment https://forums.phpfreaks.com/topic/195782-how-to-make-this-query-better/#findComment-1030192 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.