Practice Gym: The Basics
Quick warm-up challenges.
Welcome to the practice gym. Watching someone write SQL is useful, but writing it yourself is what makes it stick. Here come quick challenges, starting easy. For each one, pause the video, write your answer, and run it. Then compare with mine. It's fine if yours looks a little different. If the result is the same, you got it right.

- Writing it yourself makes it stick
- Pause, write, run
- Same result = correct
Newer books
Warm up. How many of Helen's books were published in twenty twenty three or later? Pause and try. Here's a solution. Count star, with a where on the published year. Ten books.
How many books were published in 2023 or later?
Show hint
COUNT(*) with WHERE published >= 2023
Show solution
SELECT COUNT(*) AS newer_books
FROM books
WHERE published >= 2023;โโโโโโโโโโโโโโโ โ newer_books โ โโโโโโโโโโโโโโโค โ 10 โ โโโโโโโโโโโโโโโ
First German customers
Next. Show the first three customers from Germany to join, oldest first. Show their names and join date. Pause and try. Here's a solution. Filter on the country, sort by joined, and limit three. Zane Okafor was the first.
First 3 customers from Germany to join (names, joined)
Show hint
WHERE country = 'Germany' ORDER BY joined LIMIT 3
Show solution
SELECT first_name, last_name, joined
FROM customers
WHERE country = 'Germany'
ORDER BY joined
LIMIT 3;โโโโโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโโ โ first_name โ last_name โ joined โ โโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโค โ Zane โ Okafor โ 2023-03-23 โ โ Hana โ Novak โ 2023-04-07 โ โ Nina โ Lopez โ 2023-04-10 โ โโโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโ
Cheap titles with The
Now find books with the word the in their title, that cost less than fifteen dollars, cheapest first. Pause and try. Here's a solution. Like with percent signs on both sides, and a price test. Five books, starting with The Painted Door.
Books with 'The' in the title, under $15, cheapest first
Show hint
title LIKE '%The%' AND price < 15
Show solution
SELECT title, price
FROM books
WHERE title LIKE '%The%'
AND price < 15
ORDER BY price;โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโ โ title โ price โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโค โ The Painted Door โ 12.49 โ โ Code of the River โ 12.99 โ โ The Last Lighthouse โ 13.99 โ โ The Calm Mind โ 14.49 โ โ The Silent Orchard โ 14.99 โ โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโ
Common beginner slips
Before the next round, here are the slips I see most often in these basic queries. Forgetting the quotes around text. Using double equals instead of one. Putting order by before where. And forgetting that like is case sensitive in some databases. If your query fails, check these four first.
Summary
Where, order by, limit, and like. The basics are solid. More challenges next.
Key takeaways- WHERE and AND
- ORDER BY, LIMIT
- LIKE '%word%'