Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Aptitude | GATE CS 1998 | Question 62

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Suppose we have a database consisting of the following three relations.

FREQUENTS(student, parlor) giving the parlors each student visits.
SERVES(parlor, ice-cream) indicating what kind of ice-creams each parlor serves.
LIKES(student, ice-cream) indicating what ice-creams each parlor serves.

(Assuming that each student likes at least one ice-cream and frequents at least one parlor)

Express the following in SQL:
Print the students that frequent at least one parlor that serves some ice-cream that they like.


Answer:

Explanation: Answer:

SELECT DISTINCT FREQUENTS.student FROM  
   FREQUENTS, SERVES, LIKES
   WHERE
       FREQUENTS.parlor=SERVES.parlor  
       AND
       SERVES.ice-cream=LIKES.ice-cream
       AND
       FREQUENTS.student=LIKES.student; 


Quiz of this Question

My Personal Notes arrow_drop_up
Last Updated : 17 Feb, 2021
Like Article
Save Article
Similar Reads