SQL AND and OR Operator - AND and OR Operator in SQL



Demo wikitechydatabase

  • Below is a selection from the wikitechytable table used in the examples:
sql-sql-and-or-1

AND vs OR

  • The AND operator displays a record if all the conditions are TRUE.
  • The OR operator displays a record if any of the conditions are TRUE.

AND Operator Syntax

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

OR Operator Syntax

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

The SQL AND Operator

  • The WHERE clause can contain one or many AND operators.
SELECT * FROM wikitechytable WHERE gender = 'male' AND fees <= 50

Output

sql-and-operator-2

The SQL OR Operator

  • The WHERE clause can contain one or many OR operators.
SELECT * FROM wikitechytable WHERE gender = 'Other' OR fees <= 50

Output

sql-or-operator-3

Combining AND and OR Operator

  • You can combine the AND and OR operators.
SELECT * FROM wikitechytable WHERE gender = 'female' AND (fees = 0 OR course = 'Flutter')

Output

sql-and-or-operator-4

Related Searches to SQL AND and OR Operator - AND and OR Operator in SQL