SQL SELECT Exercises

Get comfortable retrieving exactly the data you need with SQL SELECT exercises. Practice choosing columns, filtering rows with conditions, sorting results, and limiting the output. Each query runs in a real database and is checked against expected results using hidden data. Problems in this collection: 224, free: 127.

Problems in this set: 224, free: 127

Start with a free problem

SELECT and WHERE problems

Problems found: 127

Reset filters
  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Over-the-Counter Medications

    Pharmacy customers often ask which medications they can buy right away without a doctor's prescription. Return the names and prices of medications where requires_prescription = false.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Number of Berlin Customers

    The pharmacy's marketing team is planning a promotion for Berlin residents and wants to estimate its customer base there. Count the customers who listed Berlin as their city.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Platinum Loyalty Program Members

    An airline VIP manager is preparing personalized upgrades for the loyalty program's most valuable members. Return the name and country of each member with platinum status.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Number of Long-Haul Flights

    The airline's PR team is preparing a banner about the reach of its route network and wants to highlight long-distance flights.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Fitness Clubs in Berlin

    The regional director is planning an on-site audit of the chain's Berlin locations and needs a complete list of clubs in the city. Return the names of clubs whose city is Berlin.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Number of Premium Members

    To evaluate last year's upsell flow, the product team wants to know how many members currently use the Premium plan. Count those members.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Five-Star Hotels in the Chain

    A luxury concierge is putting together recommendations for a VIP client who wants only hotels in the highest star category.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Number of Rooms for More Than Two People

    A tour operator is booking a series of family trips and wants to know how many rooms across the chain can accommodate more than two people. Count the rooms where max_occupancy > 2.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Rock Artists in the Festival Database

    A talent booker is planning a series of rock festivals and putting together a shortlist of artists who fit the genre. Return the name and country of each artist whose genre is Rock.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Number of Festivals in 2024

    The annual reporting team is reviewing 2024 and wants a quick measure of the festival program’s size. Count the festivals in the database whose year is 2024.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Endangered and Critically Endangered Species

    The zoo's conservation coordinator is preparing an educational banner about rare animals. Return the names and conservation statuses of species whose status is endangered or critically_endangered.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Animal Count in the Africa Savanna Section

    The senior animal care specialist is planning how to allocate animals to a new section and first wants to know the current population of the savanna section.

What you will practice

  • Select specific columns instead of returning the entire table
  • Combine WHERE conditions using AND, OR, and parentheses
  • Sort records in ascending or descending order
  • Use LIMIT together with a meaningful ORDER BY

Common mistakes

  1. 1. Mixing AND and OR without parentheses

    AND has higher precedence than OR in SQL. Reading a condition from left to right can lead to a different interpretation than the database uses. Break complex filters into logical parts, add parentheses where needed, and test rows that meet only some of the conditions.

  2. 2. Using LIMIT without a defined order

    LIMIT restricts how many rows are returned, but it does not choose the newest, cheapest, or highest-ranked records. Without ORDER BY, the result order is not guaranteed. If a problem asks for top or latest entries, identify the sorting rule before applying LIMIT.

  3. 3. Comparing NULL with an equals sign

    NULL represents a missing value, so = NULL does not work like an ordinary equality check. The condition may silently exclude records you expected to see. Use the appropriate NULL check and consider whether records with missing values should be included or excluded.

  4. 4. Sorting numeric-looking text as numbers

    Values stored as text follow string sorting rules, which can produce a different order from numeric sorting. Dates stored as strings can cause similar surprises. Check the column's data type and inspect the first few returned rows before assuming the ordering is correct.

Theory and courses

Frequently asked questions

Are there free SQL SELECT exercises?

Yes. Free exercises in this collection: 127. With the free plan, you can sign in and solve up to 3 new problems per day without paying. Premium exercises remain visible in the catalog but require a subscription to solve.

How are my SELECT queries checked?

Your SQL runs in a real database, using PostgreSQL, MySQL, ClickHouse, or BigQuery depending on the problem. The result is automatically compared with an expected result using hidden data. This makes it worth checking the selected columns, returned rows, and required ordering carefully.

What is the difference between WHERE and ORDER BY?

WHERE determines which rows qualify for the result. ORDER BY determines their sequence. Sorting does not remove unwanted records, and filtering does not guarantee their order. Read the selection and sorting requirements separately, then make sure your query handles both.

Why does LIMIT sometimes return different rows?

Without ORDER BY, a database does not guarantee the order of returned records. LIMIT simply takes a portion of that result. If you need a predictable set of first rows, specify the sorting criteria. When values tie, an additional sorting column may be necessary.

Can I start with SELECT before learning JOIN?

Yes. Understanding tables, rows, columns, and basic filtering is enough to begin. SELECT exercises help you practice retrieving and organizing data from individual tables. Once those operations feel familiar, combining multiple tables with JOIN becomes much easier to reason about.