One-to-One and One-to-Many Relationships
You're an analyst at Brightpath, an online school. The database has three tables: students — one row per student; student_profiles — exactly one profile per student (a one-to-one relationship); and…
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 problemProblems found: 148
Reset filtersYou're an analyst at Brightpath, an online school. The database has three tables: students — one row per student; student_profiles — exactly one profile per student (a one-to-one relationship); and…
You're a junior analyst at PlayReel, a streaming service. The catalog is stored in shows, with one row per show, while seasons are stored in seasons. A show can have multiple seasons.
The accounting team is calculating quarterly bonuses and wants to see how much revenue each pharmacist generated.
Before updating membership statuses for the new season, the loyalty program coordinator wants to see how many miles each active member has accumulated.
The board of directors is discussing dividends and wants to identify the hotel with the highest revenue.
The finance team is ranking artists by earnings to support negotiations for upcoming seasons.
The investment team is reviewing the portfolio's history and wants to identify every bond that has ever been included in the bank's portfolio.
The investment team wants to identify bonds that are listed in the database but have never been held in the bank's portfolio.
The investment team is tracking the daily market value of the bank’s bond portfolio from 2024-12-01 through 2024-12-03, inclusive.
A transportation dispatcher is preparing a list of passengers departing from Vienna to share with station staff. Return the names of all passengers whose routes start in Vienna.
Snapchat is analyzing how users in different age groups split their time between sending and opening snaps.
Microsoft calls customers who have purchased at least one product from every category "Supercloud" customers. Find all of these customers and return their customer_id.
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.
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.
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.
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.
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.
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.
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.
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.
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.