Skip to content
Advertisement

SQL Find list of tuples that fulfil at least one of the conditions

Question: Find the restaurant A that fulfils at least one of the following conditions:

Conditions

  1. Restaurant A that is situated in ‘Central’ area or
  2. Restaurant A that sells at least 10 pizzas or
  3. Price of every pizza sold by A is at most $20

Expected outcomes: List with (restaurant name)

Database Schema: Customers(cname, area), Restaurants(rname, area), Pizzas(pizza), Sells(rname,pizza,price), Likes(cname, pizza)

Restaurants Table

Sells table

My SQL Query

Issue I cant seem to get the correct answer for what the question is asking for. Appreciate if you can help me to see what is wrong with my sql query.

Advertisement

Answer

I think I would use subqueries in the where clause for this:

There are ways to handle this query using JOIN and aggregation as well:

Both of these assume that the sells table has only pizzas.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement