Lab Assignment 8_Join & Sub-query
Lab Assignment 8_Join & Sub-query
Create the following tables and insert some tuples in these tables shown below. Where sid is the
primary key for the Sailors table, bid is the primary key for the Boats table and sid and bid are
the foreign keys for the Reserves table referencing to the Sailors and Boats table, respectively.
Sailors(sid: integer, sname: string, rating: integer, age: real)
Boats(bid: integer, bname: string, color: string)
Reserves(sid: integer, bid: integer, day: date)
After inserting the records in these tables, the instances should look like as follows:
Write SQL command using JOINs and/or Sub-queries for the following:
Q1. Find the names of sailors who have reserved a red or a green boat.
Q2. Find the names of sailors who have reserved both a red and a green boat.
Q3. Find the names of sailors who have reserved boat 103
Q4. Find the names of sailors who have reserved a red boat.
Q5. Find the names of sailors who have NOT reserved a red boat.
Q6. Find the names of sailors who have reserved at least one boat.
Q7. Find sailors whose rating is better than some sailor called Horatio.
Q8. Find sailors whose rating is better than every sailor called Horatio.
Q9. Find the sailors with the highest rating.
Q10. Find the names of sailors who have reserved all boats.