DCJones DCJones - 3 months ago 9
MySQL Question

MySQL returning all the records from the left table excluding the records that have a match in the right table

I am trying to return records from Table1 where there is not a match in Table2.

My code is:

SELECT *
FROM Table1 c
LEFT JOIN
Table2 a
ON c.TableID = a.TableID
WHERE c.TableID NOT IN (SELECT a.TableID FROM Table2)


I have tried to right this many times without success. Can anyone please help.

Many thanks in advance for your time.

Answer

Replace 'where' with this:

WHERE a.TableID IS NULL