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); 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. 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 Link to comment https://forums.phpfreaks.com/topic/51584-slow-mysql-queries/#findComment-254259 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.