Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose we have a relation SocialNetwork(Person, Friend) which gives immediate friends of a person. A person may have many friends. This SocialNetwork relation is similar

Suppose we have a relation SocialNetwork(Person, Friend) which gives immediate friends of a person. A person may have many friends. This SocialNetwork relation is similar to Twitter in that friendship relationship is not necessarily bi-directional. This implies that if a tuple of SN says that A is a friend of B, then it does not imply that B is a friend of A. If B is a friend of A, which is possible, then it will be identified by another tuple. We want to define a recursive relation Follows whose pairs (p,f) are persons such that f was either a friend of p, or a friend of a friend, or so on.

a) Write a definition of Follows as a SQL recursion.

b) Write a SQL query that returns the set of pairs (p,f) such that friend f follows person p, but is not an immediate friend of p.

c) Write a recursive SQL query that returns the set of pairs (p,f) such that f is a follow-on of p, but is neither a friend nor a friend of a friend.

d) Write a recursive SQL query that returns the set of pairs (p,f) such that f is a follow-on of p but f has at most one friend.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions