Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Returning all data from a table
Select some columns
Filtering rows
Logic
9. Logical operators – OR
Text patterns
To be or NULL to be
A bit of mathematics
Let's practice

Instruction

Up until now, we were able to filter the rows in the previous examples using conditional operators (=, !=, <, >, <=, >=). But what about situations when we want to be really picky and join a few conditions?

SELECT
  Id,
  Name
FROM User
WHERE Age > 50
  OR Height < 185;

In the above query, we added a new OR clause that allows us to join more conditions.

In this case, we only select those users who are older than 50 or under 185 cm in height. In other words, a row will appear in the result set when either the first or second condition is true for that row. Of course, if both conditions are true, the row will still be displayed.

Exercise

Select the Vin of all cars produced before 2005 or priced at less than 10,000.

Stuck? Here's a hint!

Type:

SELECT
  Vin
FROM Car
WHERE ProductionYear < 2005
  OR Price < 10000.00;