Using the following relational schema: Sailors (S_ID, S_name, S_rating, S_Age) B
ID: 3918644 • Letter: U
Question
Using the following relational schema:
Sailors (S_ID, S_name, S_rating, S_Age)
Boats (B_ID, B_name, B_color)
Reservations (S_ID, B_ID, R_date)
Explanation / Answer
Please find below answers:
1. Query 1: Whenever Select statement names multiple tables in the FROM Clause, it performs the full JOIN. so from this query you will get A x B x C number of rows.
Lets say sailor table has 5 rows(A)
reserves table has 6 rows(B)
and boat table has 7 rows(C)
So total number of records you will get is 5 x 6 x 7 = 210 rows in result. Using this query you will get multiple same combination for s.sname and b.bname in resultset.
Using this query you wont be able to identify if sailor has reseved that boat or not.
Query 2: In this query we are optimizing the above results by applying conditions in where clause such as applying comparison on same column of different table.
by running this query you will get results of only rows where sid of sailor table matches with the sid of reserves tabl and bid of boats table matches with that of reserves table and boat color is red.
so in short you will get name of sailors and name of his reserved red boat.
2. Query 1: this query performs self join on reserves table where boat id is not same then it shows the sailor's name number of times he has unique reservations against every boat and have more than one reservation.
LEts say sailor 1 has 4 reservations for boat as below
rid 1, bid1
rid2, bid 2
rid3, bid 2,
rid4, bid3,
Then sailor 1 has 3 unique reservations. so you will sailor 1 name three times in resultset.
Query 2: in above query, we are getting sailors name multiple times , so in order to solve this problem we have used distinct on sailor name which will display sailors name only once. so in short you will get names of sailors who have more than one reservation.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.