Azu Posted May 16, 2007 Share Posted May 16, 2007 Would somebody please tell me why these MySQL queries are running so slow and how I can optimize them? select count(*) from Z where X not in (select 1 from a) and X not in (select 2 from b) and X not in (select 3 from c); delete from Z where X not in (select 1 from a) and X not in (select 2 from b) and X not in (select 3 from c); Quote Link to comment https://forums.phpfreaks.com/topic/51584-slow-mysql-queries/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 16, 2007 Share Posted May 16, 2007 Possibly?: SELECT count(*) FROM Z WHERE X NOT IN ( SELECT 1 FROM a UNION SELECT 2 FROM b UNION SELECT 3 FROM c ) EDIT: the above query is not faster. Quote Link to comment https://forums.phpfreaks.com/topic/51584-slow-mysql-queries/#findComment-254236 Share on other sites More sharing options...
bubblegum.anarchy Posted May 16, 2007 Share Posted May 16, 2007 This is pretty much the same as your original query Azu: SELECT count(*) FROM Z LEFT JOIN a ON Z.1 = a.1 LEFT JOIN b ON Z.1 = b.1 LEFT JOIN c ON Z.1 = c.1 WHERE a.1 IS NULL AND b.1 IS NULL AND c.1 IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/51584-slow-mysql-queries/#findComment-254259 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.