For my assessment I have to obtain such result from mysql database:
+---------------------------------------+---------------------------------------+-------+
| name | name | item |
+---------------------------------------+---------------------------------------+-------+
| Krispy Kreme - Edinburgh Lothian Road | 6 Assorted Doughnuts | 12.95 |
| Krispy Kreme - Edinburgh Lothian Road | Original Glazed Dozen | 14.95 |
| Krispy Kreme - Edinburgh Lothian Road | Original Glazed Double Dozen | 23.95 |
| Krispy Kreme - Edinburgh Lothian Road | Sharer Dozen | 17.95 |
| Krispy Kreme - Edinburgh Lothian Road | Original Glazed & Sharer Double Dozen | 24.95 |
| Krispy Kreme - Edinburgh Lothian Road | Sharer Double Dozen | 27.95 |
+---------------------------------------+---------------------------------------+-------+
Show the name and delivery menu item for the restaurant where everything costs more than £10.
- that’s the question.
I’ve tried this
SELECT restaurant.name AS "restaurant name", food_item.name AS "item name",
food_item.price AS "item price"
FROM restaurant
JOIN food_item ON restaurant.id = food_item.restaurant_id AND
food_item.price
WHERE food_item.price > 10;
but I receive all the items that cost more than 10, but I need to receive the answer mentioned above, without specifying the name. I have to exclude all the restaurants that has positions in their menu that cost less than 10.
ERD is attached
2
Answers
If I understand you correct, you want to get all the prices from all the restaurants.
But if a restaurant has items in their menu that costs less than 10, nothing from that restaurant will be returned.
In that case, you have to add a subquery like the example here.
Be aware that it is untested, but it should give you an idea:
If you need to exclude a restaurant if any of its menu options cost 10 or less, this can be expressed as a not exists semi-join.
Also note how, below, providing some short meaningful aliases helps make the query more compact and readable: