Home > Enterprise >  SQL filter 3 columns of a table
SQL filter 3 columns of a table

Time:11-16

I have a table as below:

Original table

enter image description here

I want to use SQL to filter out any records Type= 'B' or any records ID=1 or any records Color='red'. I can filter out step by step. Could I do it once. I tried the Where Type <> 'B' OR ID <> 1 OR Color <> 'red' in SQL Server. But it doesn't work. Could someone help? Thanks!

The expected result should be:

enter image description here

CodePudding user response:

What you are saying, in SQL:

...
WHERE
 NOT (TYPE='B'
      OR ID=1
      OR Color='red')

or, applying the OR operator to the parenthesised section:

...
WHERE
    TYPE<>'B'
    AND ID<>1
    AND Color<>'red'
  • Related