Either Condition with OR

With AND, a row must meet all the conditions. With OR, one of them is enough: the row gets into the result when at least one of the conditions is true for it. It doesn't matter which one, and it can be both. The racing and the sports games:

SELECT title, genre
FROM games
WHERE genre = 'Racing'
   OR genre = 'Sports'
ORDER BY title;
titlegenre
Goal RushSports
Ice Hockey ProSports
Pixel RacerRacing
Turbo KartsRacing

Notice the “and” in “the racing and the sports games”. You want both kinds of games, but no game is a racing game and a sports game at the same time, so genre = 'Racing' AND genre = 'Sports' would find nothing. When you turn a request into SQL, think about one row: must it meet both conditions, or is one enough? Here, one is enough, so it's OR.

The conditions can be about different columns. The games that are very cheap or for adults only:

SELECT title, price, age_rating
FROM games
WHERE price < 10
   OR age_rating = 18
ORDER BY title;
titlepriceage_rating
Cube Logic53
Zombie Town3018

Typical mistake: the column written only once. This query isn't an error, but it finds only the racing games:

SELECT title, genre
FROM games
WHERE genre = 'Racing' OR 'Sports'
ORDER BY title;
titlegenre
Pixel RacerRacing
Turbo KartsRacing

OR joins two complete conditions, and 'Sports' alone isn't a condition, just a text. SQLite takes such a text for false, so only the first condition is left. Write the column in each condition: genre = 'Racing' OR genre = 'Sports'.

Instructions

The query in the editor should show the customers from London or Leeds, but it shows only those from London. Fix it. The result is sorted by name and starts like this:

namecity
Emma ClarkLondon
Grace HallLondon
Isla YoungLeeds
……

Below it, show the title and the price of the games that cost less than $15 or more than $45, sorted by price:

titleprice
Cube Logic5
Word Quest10
Goal Rush50
Knight's Oath60

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

5/11