79119523

Date: 2024-10-23 19:59:42
Score: 1
Natty:
Report link

I know this an older question so I wanted to give an update for a method that executes much more quickly. You can utilize WHERE NOT EXISTS...

SELECT number FROM TableA WHERE NOT EXISTS (SELECT number FROM B WHERE TableA.number = TableB.number);

While I am not near any documentation I suspect "NOT EXISTS" instructs MySQL to search through the first query once while "NOT IN" has the query executing each record. It takes .3 seconds in my database for "NOT EXIST" to return 340,000 records while "NOT IN" takes 10 seconds to return a limit of 100 records. NOT EXISTS may have not existed the 12 or so years ago this question was answered, I do not know...

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Nicholas Seamans