Lesson 4: Review & Practice – Crafting Real-World SELECT Queries

You've built a strong foundation with the basics of SQL:

  • Retrieving data using SELECT
  • Filtering results using WHERE
  • Removing duplicates with DISTINCT
  • Sorting with ORDER BY
  • Limiting results with LIMIT and OFFSET

Now it's time to take a step back, review what you've learned, and apply your knowledge to practical questions — just like you would in real projects.

In this review lesson, you'll revisit core query syntax, analyze real-world questions, and practice combining multiple SQL clauses to answer them. These tasks will strengthen your skills and boost your confidence before we dive into joins and aggregations in upcoming lessons.

🔄 Core Query Structure Recap

Here's the basic format of a flexible SQL query that uses everything you've learned so far:

SELECT column1, column2 
FROM table_name 
WHERE condition 
ORDER BY column1 DESC 
LIMIT 5 OFFSET 10;

This single query structure can be shaped to answer a wide range of data questions by combining the different clauses you've mastered.

Remember the execution order:

  1. FROM - Get data from the table
  2. WHERE - Filter rows based on conditions
  3. SELECT - Choose which columns to display
  4. DISTINCT - Remove duplicate rows (if used)
  5. ORDER BY - Sort the results
  6. LIMIT/OFFSET - Limit the number of results returned

🏛️ Meet Your New Dataset: top_universities

Let's switch things up! Instead of movies, you'll now be working with a new dataset featuring some of the world's top universities. This will give you practice applying your SQL skills to different types of data.

The top_universities table structure:

id | university_name        | country     | city      | student_count | founded_year
---|------------------------|-------------|-----------|---------------|-------------
1  | Harvard University     | USA         | Cambridge | 21000         | 1636
2  | University of Oxford   | UK          | Oxford    | 24000         | 1096
3  | Stanford University    | USA         | Stanford  | 17000         | 1885
4  | University of Tokyo    | Japan       | Tokyo     | 28000         | 1877
5  | ETH Zurich             | Switzerland | Zurich    | 23000         | 1855

This table contains information about university names, locations, student populations, and founding years — perfect for practicing your filtering and sorting skills!


🧭 Common Pitfalls (And How to Avoid Them)

As you work through these exercises, watch out for these common mistakes:

🚫 Forgetting SELECT before FROM Always start your queries with what you want to retrieve.

-- ❌ Wrong
FROM top_universities WHERE country = 'USA';

-- ✅ Correct
SELECT university_name FROM top_universities WHERE country = 'USA';

🚫 Using = instead of LIKE (or vice versa) Remember = works for exact matches. LIKE is for patterns (we'll dive deeper in a future lesson).

-- For exact matches
WHERE country = 'USA'

-- For pattern matching (future lesson)
WHERE university_name LIKE '%University%'

🚫 Using ORDER BY without specifying ASC or DESC It defaults to ascending (ASC), but it's best to be explicit — especially when showing top results.

-- ❌ Unclear intention
ORDER BY student_count

-- ✅ Clear intention
ORDER BY student_count DESC  -- Largest first

🛠️ Problem-Solving Approach

If you're stuck on a query, try breaking it into steps. Think about:

  1. What do I want to see?SELECT
  2. Where does the data come from?FROM
  3. Should I filter some rows?WHERE
  4. Do I need to sort or limit?ORDER BY, LIMIT, OFFSET

Example thought process: "Find the 3 universities with the most students"

  1. I want to see: university names and student counts
  2. Data comes from: top_universities table
  3. Filter: No filtering needed
  4. Sort: By student_count DESC, limit to 3 results
SELECT university_name, student_count 
FROM top_universities 
ORDER BY student_count DESC 
LIMIT 3;

✅ What You Should Be Able to Do After This

By now, you should feel comfortable with:

  • Writing SELECT queries from scratch without hesitation
  • Filtering data using various conditions with WHERE
  • Sorting and slicing result sets to get exactly what you need
  • Answering analytical questions using SQL with confidence
  • Combining multiple clauses to create powerful, targeted queries
  • Debugging queries by breaking them down into logical steps
  • Working with different data types (text, numbers, dates)

💡 Pro Tip: The best way to master SQL is through practice. Don't just complete the exercises — try variations! Change the conditions, sort by different columns, or combine multiple filters. The more you experiment, the more confident you'll become.


📝 Exercise Overview

In this lesson's practice section, you'll work with the top_universities table to solidify your understanding of fundamental SQL concepts.

You'll practice:

  • Finding largest universities - Working with numerical data and sorting
  • Filtering by founding year - Using comparison operators with dates
  • Retrieving specific columns - Practicing targeted data selection
  • Combining conditions - Using multiple filters to find specific results
  • Working with unique values - Applying DISTINCT to real data

Each exercise is designed to reinforce a key concept while building your confidence with different types of data scenarios. Take your time, experiment with variations, and remember that making mistakes is part of the learning process.

After completing these exercises, you'll be ready to tackle more advanced topics like combining data from multiple tables with JOINs — where SQL really starts to shine and gets closer to real-world database work!


Ready to practice SQL? Try our coding challenges →