SQL AND, OR and NOT Operators

The where clause is combined with AND , OR and NOT operators.

OperatorDefinitionExampleResult
ANDReturns true if both conditions are trueSELECT * FROM table WHERE column1 = ‘value1’ AND column2 = ‘value2’Returns all rows where both column1 is ‘value1’ and column2 is ‘value2’
ORReturns true if at least one condition is trueSELECT * FROM table WHERE column1 = ‘value1’ OR column2 = ‘value2’Returns all rows where either column1 is ‘value1’ or column2 is ‘value2’
NOTNegates a conditionSELECT * FROM table WHERE NOT column1 = ‘value1’Returns all rows where column1 is not ‘value1’

example:

Output:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top