SQL
Operators

WHERE clause could be used with AND, OR and NOT operators. AND and OR operators are used to filter records based on more than one condition.

  • AND operator is used where we want to display record if all the conditions separated by AND is TRUE.
  • OR operator is used where we want to display record if any of the condition separated by OR is TRUE.
  • NOT operator display a record if the condition is NOT TRUE.

AND Operator

Syntax

  

    SELECT DISTINCT column1, column2....columnN
    FROM   table_name
    WHERE condition1 AND condition2....columnN;

Example


    SELECT * FROM Customers
    WHERE Country='pakistan' AND City='sargodha';

OR Operator

Syntax


    SELECT DISTINCT column1, column2....columnN
    FROM   table_name
    WHERE condition1 OR condition2...;

Example


    SELECT * FROM Customers
    WHERE Country='pakistan' AND City='sargodha';

NOT Operator

Syntax


    SELECT DISTINCT column1, column2....columnN
    FROM   table_name
    WHERE NOT condition;

Example


    SELECT * FROM Customers
    WHERE NOT Country='USA';