2

Is there any way to optimise this query to something quicker?

SELECT id FROM business 
WHERE id NOT IN(SELECT business_id FROM business_community GROUP BY business_id)
ajreal
  • 46,720
  • 11
  • 89
  • 119
gumpi
  • 281
  • 1
  • 4
  • 13
  • I am not sure if a left join followed by a `NULL` check would be faster, but I think it's worth trying. – lijie Dec 10 '10 at 14:25
  • Just for reference, it is a bug in mysql -> http://stackoverflow.com/questions/3417074/why-would-an-in-condition-be-slower-than-in-sql – Itay Moav -Malimovka Dec 10 '10 at 14:37

2 Answers2

5

Try this:

SELECT id FROM business AS b
LEFT JOIN business_community bc ON bc.business_id = b.id
WHERE bc.business_id IS NULL
Marek Kwiendacz
  • 9,524
  • 14
  • 48
  • 72
0

Maybe using "DISTINCT business_id" rather than a group by..

kgautron
  • 7,915
  • 9
  • 39
  • 60