AnalystPath

Espresso Drinkers Who Skip Matcha

SQLEasyJunior level~15 min

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
drink_iddrink_nameprice_cents
1Espresso350
2Latte450
3Matcha500
ordering
barista_iddrink_idguest_idordered_oncupstotal_cents
1112021-01-212700
1222021-02-171450
2132021-06-021350

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

Related SQL questions