Select all except some rows

If you want to deselect some rows dynamically, you may use it:

SELECT * FROM `table_1` WHERE id NOT IN (SELECT id FROM `table_2` WHERE column_name='value')

NOTE: Here, id is a column_name, which both tables have in common.

Good luck. :)


... WHERE NOT (model = 'Ford' AND color = 'yellow')

In addition to Foo Bah's answer,

if you have null column values like that;

NAME      COLOR

Ford      green               
Ford      red                 
Subaru    yellow              
Subaru    red                 
Subaru    NULL
Ford      NULL              

you need to use ISNULL() function to bring null column values

... WHERE  NOT (ISNULL(NAME,'') = 'Ford' AND ISNULL(COLOR,'') = 'yellow')

Tags:

Sql