Skip to content
Advertisement

select from where field not equal to field in other table

I am running the following script in SQLite3:

This script throws an error when I run it:

Error: near line 30: no such column: C.a

The idea here is that I would like to make a selection from B where field a is not equal to 1, 3 or 5. Is it not possible to refer to columns from other tables within the same SQL statement? How to achieve this?

EXPECTED RESULT

Advertisement

Answer

This requirement can be expressed with NOT EXISTS like this:

For every row of B if B.a does not exist in C then NOT EXISTS is TRUE and that row is returned.

Or with a LEFT JOIN from which only the unmatched rows of B are returned:

See the demo.
Results:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement