Dishes Present in Only One Cuisine Type
MediumSQLPractice library · +20 XPset operationssqlsubquery
A restaurant owner wants to analyze their menu to understand the uniqueness of their offerings.
They have two tables:
dishes:dish_id(INT, PK),dish_name(VARCHAR(100))cuisine_dishes:cuisine_id(INT, PK),dish_id(INT, PK, FK to dishes.dish_id)
Return the dish_name of dishes that appear in exactly one cuisine type. The output should be ordered alphabetically by dish_name.
Tables
CREATE TABLE dishes ( dish_id INT PRIMARY KEY, dish_name VARCHAR(100) NOT NULL ); CREATE TABLE cuisine_dishes ( cuisine_id INT NOT NULL, dish_id INT NOT NULL, PRIMARY KEY (cuisine_id, dish_id), FOREIGN KEY (dish_id) REFERENCES dishes(dish_id) );
Example data
INSERT INTO dishes (dish_id, dish_name) VALUES (1, 'Butter Chicken'), (2, 'Paneer Tikka'), (3, 'Biryani'), (4, 'Dal Makhani'), (5, 'Naan'), (6, 'Sushi'), (7, 'Ramen'), (8, 'Tempura'), (9, 'Pho'), (10, 'Banh Mi'); INSERT INTO cuisine_dishes (cuisine_id, dish_id) VALUES (1, 1), -- Indian (1, 2), (1, 3), (1, 4), (1, 5), (2, 6), -- Japanese (2, 7), (2, 8), (3, 9), -- Vietnamese (3, 10), (1, 6); -- Indian and Japanese: Sushi
Your query is also checked on hidden datasets with different data.
Hints
Similar problems
- Find Interns with Above Average SalaryMedium
- Top 3 Interns by Monthly Stipend in Each DepartmentMedium
- Customers with No OrdersMedium
- Top 2 Interns by Monthly Stipend in Each DepartmentMedium
- Rank Student Scores in Each SubjectMedium
- Student Course Ranking by SemesterMedium
More in: SQL and Databases problems
-- Write your query here
SELECT dish_name
FROM dishes
Your query runs on the example tables shown with the problem, then on hidden datasets when you submit.
Write standard SQL. MySQL habits work too: IFNULL, IF, YEAR(), DATE_FORMAT, GROUP_CONCAT, `backticks` and LIMIT 5, 10. It runs on PostgreSQL, so integer division keeps whole numbers (5 / 2 = 2): write 5.0 / 2 for 2.5.