Get startedGet started for free

WHERE AND OR

What if you want to select rows based on multiple conditions where some but not all of the conditions need to be met?

For this, SQL has the OR operator.

For example, the following returns all details from bank clients that are either 29 or 41 years old:

SELECT *
FROM clients
WHERE age = 29
OR age = 41;

Note that you need to specify the column for every OR condition!

When combining AND and OR, be sure to enclose the individual clauses in parentheses, like so:

SELECT *
FROM clients
WHERE (age = 29 OR age = 41)
AND (education = 'university degree' OR certification = 'R');

Otherwise, due to SQL's precedence rules, you may not get the results you're expecting!


What does the OR operator do?

This exercise is part of the course

SQL Tutorial for Marketers

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise