Kshitij Saxena -KJ- Kshitij Saxena -KJ- - 2 years ago 115
SQL Question

MySQL "NOT IN" query

I wanted to run a simple query to throw up all the rows of

where a principal column value is not present in a column in another table (

I tried using:

SELECT * FROM Table1 WHERE Table1.principal NOT IN Table2.principal

This is instead throwing a syntax error. Google search led me to forums where people were saying that MySQL does not support
and something extremely complex needs to be used. Is this true? Or am I making a horrendous mistake?

Answer Source

To use IN, you must have a set, use this syntax instead:

SELECT * FROM Table1 WHERE Table1.principal NOT IN (SELECT principal FROM table2)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download