0

New to SQL. Hope to find distinct pizza sold by restaurants that are located in the same area as bob (customer).

Database schema:

Customers(cname, area)

Restaurants(rname, area)

Pizzas(pizza)

Sells(rname,pizza,price)

Likes(cname, pizza)

   SELECT distnct pizza
   FROM Sells
   WHERE rname in (
      SELECT rname
      FROM Restaurants
      WHERE area..... 
   -- This is the part where i don't know how to continue. 
   -- How do i write it so that i compare the location of the restaurant with bob's location? 
   );
0

Seems to me that a combination of an INNER JOIN and EXISTS should do:

SELECT DISTINCT(s.pizza)
FROM dbo.Sells s
INNER JOIN dbo.Restaurants r
    ON s.rname = r.rname
WHERE EXISTS(SELECT 1 FROM dbo.Customers
             WHERE cname = 'bob'
             AND area = r.area) 
;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy