Espresso Drinkers Who Skip Matcha
Problem
A cafe logs every drink a guest orders.
Table: drink
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| drink_id | int |
| drink_name | varchar |
| price_cents | int |
+-------------+---------+
drink_id is the primary key. Each row describes a drink on the menu.
Table: ordering
+-------------+------+
| Column Name | Type |
+-------------+------+
| barista_id | int |
| drink_id | int |
| guest_id | int |
| ordered_on | date |
| cups | int |
| total_cents | int |
+-------------+------+
This table may contain duplicate rows. Each row records one order placed by a guest.
Write a solution that reports the distinct guests who have ordered 'Espresso' but have never ordered 'Matcha'. Return the result in any order with a single column guest_id.
Tables
Example rows — the live problem includes the full dataset.
| drink_id | drink_name | price_cents |
|---|---|---|
| 1 | Espresso | 350 |
| 2 | Latte | 450 |
| 3 | Matcha | 500 |
| barista_id | drink_id | guest_id | ordered_on | cups | total_cents |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2021-01-21 | 2 | 700 |
| 1 | 2 | 2 | 2021-02-17 | 1 | 450 |
| 2 | 1 | 3 | 2021-06-02 | 1 | 350 |
Expected output
Your answer should return 1 row with the columns guest_id.
Starter code (SQL)
SELECT *
FROM drink;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