Dishes Present in Only One Cuisine TypeMedium

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