soma56 Posted April 30, 2012 Share Posted April 30, 2012 Hi, I'm new to mysql and wanted to know if something like this was possible: $query = "SELECT * FROM tableX WHERE status != 'Error' AND id != (SELECT id FROM tableY) LIMIT 1"; $get_incomplete_keyword = mysql_query($query); The idea is to only select from table 'x' where the id is NOT in table 'Y'. Is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/261852-select-all-from-x-where-id-isnt-found-in-table-y-is-this-query-possible/ Share on other sites More sharing options...
awjudd Posted April 30, 2012 Share Posted April 30, 2012 -- Slow SELECT * FROM tableX WHERE status != 'Error' AND id NOT IN (SELECT id FROM tableY) LIMIT 1 -- Faster (should work ... ish) SELECT * FROM tableX AS x LEFT JOIN tableY AS y ON x.id=y.id WHERE x.status != 'Error' AND y.id IS NULL Please Note: the NOT EQUALS and NOT IN are pretty slow options (can't use indexes). ~awjudd Quote Link to comment https://forums.phpfreaks.com/topic/261852-select-all-from-x-where-id-isnt-found-in-table-y-is-this-query-possible/#findComment-1341742 Share on other sites More sharing options...
soma56 Posted April 30, 2012 Author Share Posted April 30, 2012 Thanks, works perfect. Quote Link to comment https://forums.phpfreaks.com/topic/261852-select-all-from-x-where-id-isnt-found-in-table-y-is-this-query-possible/#findComment-1341749 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.