AnalystPath

Chefs Who Tasted Their Own Dish

SQLEasyJunior level~15 min

Problem

Table: `Tastings`

```text
+------------+---------+
| Column | Type |
+------------+---------+
| dish_id | int |
| chef_id | int |
| taster_id | int |
| taste_day | date |
+------------+---------+
There is no single-column primary key. Each row means taster_id tasted the
dish dish_id, which was created by chef_id, on taste_day.
```

Find every chef who tasted at least one of their own dishes (the chef and the
taster are the same person). Return one row per such chef. Use the column
heading `id` and sort the result by `id` in ascending order.

**Example**

```text
Tastings:
+---------+---------+-----------+------------+
| dish_id | chef_id | taster_id | taste_day |
+---------+---------+-----------+------------+
| 1 | 5 | 5 | 2024-01-01 |
| 2 | 5 | 7 | 2024-01-01 |
| 3 | 8 | 8 | 2024-01-02 |
| 4 | 9 | 5 | 2024-01-03 |
+---------+---------+-----------+------------+

Output:
+----+
| id |
+----+
| 5 |
| 8 |
+----+
```

Chef 5 tasted dish 1 (their own) and chef 8 tasted dish 3 (their own).

Tables

Example rows — the live problem includes the full dataset.

Tastings
dish_idchef_idtaster_idtaste_day
1552024-01-01
2572024-01-01
3882024-01-02

Expected output

Your answer should return 2 rows with the columns id.

Starter code (SQL)

SELECT *
FROM Tastings;

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