Members Who Booked Yoga and Spin but Not Boxing
Problem
A fitness studio records every class a member books. The studio wants the members who have booked both the `Yoga` class and the `Spin` class but have never booked the `Boxing` class.
Table: `members`
| Column | Type |
|-------------|---------|
| member_id | int |
| member_name | varchar |
`member_id` is the primary key.
Table: `bookings`
| Column | Type |
|-------------|---------|
| booking_id | int |
| member_id | int |
| class_name | varchar |
`booking_id` is the primary key. Each row is one class booking by a member.
Write a query that returns the `member_id` and `member_name` of every member who has booked `Yoga` and `Spin` but has not booked `Boxing`. Return the rows ordered by `member_id`.
Tables
Example rows — the live problem includes the full dataset.
| member_id | member_name |
|---|---|
| 1 | Priya |
| 2 | Marco |
| 3 | Elena |
| booking_id | member_id | class_name |
|---|---|---|
| 10 | 1 | Yoga |
| 20 | 1 | Spin |
| 30 | 1 | Pilates |
Expected output
Your answer should return 1 row with the columns member_id, member_name.
Starter code (SQL)
SELECT *
FROM members;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock