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
<?php  

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

?>


Example
<?php  

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

?>

OR Operator

Syntax
<?php  

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

?>


Example
<?php  

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

?>

NOT Operator

Syntax
<?php  

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

?>


Example
<?php  

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

?>

Copyright © PHPDocs 2017