Select all except some rows Select all except some rows sql sql

Select all except some rows


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


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. :)


In addition to Foo Bah's answer,

if you have null column values like that;

NAME      COLORFord      green               Ford      red                 Subaru    yellow              Subaru    red                 Subaru    NULLFord      NULL              

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

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