SQL JOIN Practice Problems

Practice SQL JOIN with problems that go beyond matching two tables. Work with customers, orders, employees, and other related data to find records, combine information, and calculate results. Your queries run in a real database and are automatically checked against expected results using hidden data. Problems in this set: 148, free: 26.

Problems in this set: 148, free: 26

Start with a free problem

JOIN problems

Problems found: 86

Reset filters
  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Updated Advertiser Status Based on Payments

    Facebook recalculates advertiser statuses every day. For each advertiser in advertiser, determine a new status: EXISTING if daily_pay, which contains today's payments, has a payment from that…

    Facebook (Meta)
  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Rank Fans by Concerts Attended

    The band's loyalty program is ranking superfans by the number of concerts they have attended.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Club Members' Expenses in 2005

    A book club wants to identify its most active readers in 2005 by their total borrowing expenses. For each club member, calculate the total cost of books they borrowed that year.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Book Rental Expenses in June 2005

    The club wants to know who was active during its summer reading marathon in June 2005.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Spending by Genre in 2005

    The club needs a breakdown of spending by genre for 2005 for its quarterly report.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Fans Who Attended Club Concerts in Moscow

    A local fan club is preparing invitations to an after-party in Moscow, but only fans who have attended club concerts there should receive them.

  • MediumPremium
    PostgreSQL · MySQL

    Tour Attendance

    The finance department needs attendance figures for each tour to calculate royalties. For each tour, return its id, departure city, arrival city, and number of fans who attended.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Oldest Patient in Cardiology

    A geriatric consultant is planning follow-up care and wants to know the maximum age among patients in cardiology wards. For this task, cardiology wards are those whose codes start with CARD.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Cabins with Bookings in Week 12 of 2020

    An analyst is preparing a cabin occupancy report for ISO calendar week 12 of 2020. Return all columns from Cabins for cabins that have at least one booking that started during that week.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Revenue by Captain

    The platform pays captains a percentage of the bookings for their cabins and produces a monthly ranking.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Percentage of Active Passengers

    The product team wants to know what percentage of registered passengers actually use the service—that is, have booked at least one cabin.

  • MediumPremium
    PostgreSQL · MySQL · ClickHouse

    Captain or Guest

    The platform divides users into those who earn money through the service and those who use it: captains own cabins, while guests book trips. All users are stored in Passengers.

What you will practice

  • Choose the right JOIN type for the expected result
  • Identify the keys that connect two or more tables
  • Keep unmatched records with LEFT JOIN when needed
  • Understand how JOIN conditions and WHERE filters interact

Common mistakes

  1. 1. A JOIN creates unexpected duplicates

    When one customer has several orders, joining the tables produces several rows for that customer. This can inflate counts and sums. Check whether the join keys are unique on either side, and compare the number of rows before and after the JOIN.

  2. 2. A WHERE filter removes unmatched rows

    A LEFT JOIN fills columns from the missing right-hand record with NULL. Filtering those columns in WHERE can remove the unmatched rows you intended to keep. Check whether records without matches are still present, and decide whether the condition belongs in ON or WHERE.

  3. 3. The wrong columns are joined

    Two columns with similar names are not necessarily related. Joining them can produce no matches or, worse, convincing but incorrect pairs of records. Check what each key represents, whether the data types are compatible, and whether a few known relationships appear correctly in the result.

  4. 4. INNER JOIN hides missing relationships

    INNER JOIN returns only matching records. If the problem asks for customers without orders or pages without likes, those rows will disappear. Before writing the query, decide whether unmatched records belong in the output. Test your choice using records that have no corresponding row.

Theory and courses

Frequently asked questions

Can I practice SQL JOIN for free?

Yes. Free problems in this set: 26. You can solve them without paying. After signing in, the free plan allows up to 3 new problems per day. Premium problems are visible in the list but require a subscription to solve.

Does the trainer show the correct JOIN query?

Reference solutions are not published. You write your own SQL, which runs against a real database. The trainer automatically checks the result against an expected result using hidden data. Problems include hints and an AI mentor to help you work through the logic.

When should I use LEFT JOIN instead of INNER JOIN?

Think about which rows must appear in the result. Use LEFT JOIN when every row from the left table should remain, even without a matching record on the right. INNER JOIN is appropriate when you only need matches. The difference becomes clear when you test missing relationships.

Why does my JOIN return more rows than expected?

The relationship may be one-to-many or many-to-many. A single row from one table can match several rows in another, producing multiple output rows. That is not always a mistake. First decide whether the problem expects every matching pair or one result per entity.

Do I need GROUP BY to solve JOIN problems?

Not always. Some problems only require connecting tables and selecting the right records. Others ask you to count related rows, calculate totals, or summarize the joined data. Start with straightforward joins, then move to problems that combine JOIN with aggregation.