AnalystPath

Members Who Booked Yoga and Spin but Not Boxing

SQLMediumMid level~15 min

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.

members
member_idmember_name
1Priya
2Marco
3Elena
bookings
booking_idmember_idclass_name
101Yoga
201Spin
301Pilates

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

Related SQL questions