Title: Sailors sid: integer, sname: string, rating: integer, age: real
1Sailors( sid integer, sname string, rating
integer, age real) Reserves( sid integer, bid
integer, day date)
Figure 1 an instance S1 of Sailors
2Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
DB
3Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
4Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
5Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
6Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
7Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
8Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
9Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
10Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
11Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
12Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
13Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
14Q1. Find the names and ages of all sailors.
SELECT S.sname, S.age FROM Sailors S
Result
DB
15Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
DB
16Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
17Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
18Q2. Find all sailors with a rating above 7.
7gt7?
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
No!
Result
DB
19Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
20Q2. Find all sailors with a rating above 7.
8gt7?
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Yes!
Result
DB
21Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
22Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
23Q2. Find all sailors with a rating above 7.
10gt7?
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Yes!
Result
DB
24Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
25Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
26Q2. Find all sailors with a rating above 7.
10gt7?
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Yes!
Result
DB
27Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
28Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
29Q2. Find all sailors with a rating above 7.
9gt7?
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Yes!
Result
DB
30Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
31Q2. Find all sailors with a rating above 7.
SELECT S.sid, S.sname FROM Sailors S WHERE
S.ratinggt7
Result
DB
32Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.name FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
DB (new)
Figure 3 Instance of Reserves
Figure 2 Instance of Sailors
This query requires information from both
tables. To answer this query requires a JOIN
operation to be performed
33Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
A join operation roughly works as follows we
start with a row in table Sailors So, this
JOIN requires about O(nm) operations Where n
Reserves
34Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
Reserves
35Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
Reserves
36Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 22
Reserves
37Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 22
R.sid 22
S.sid R.sid!
Reserves
38Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 22
R.sid 22
S.sid R.sid!
R.bid 101
101 ? 103!
Reserves
39Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 22
R.sid 58
S.sid ? R.sid!
Reserves
40Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
Reserves
41Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 31
Reserves
42Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 31
R.sid 22
S.sid ? R.sid!
Reserves
43Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 31
R.sid 58
S.sid ? R.sid!
Reserves
44Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
Reserves
45Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 58
Reserves
46Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 58
R.sid 22
S.sid ? R.sid!
Reserves
47Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 58
R.sid 58
S.sid R.sid!
Reserves
48Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
S.sid 58
R.sid 58
S.sid R.sid!
R.bid 103!
Reserves
49Q3. Find the names of sailors who have reserved
boat number 103.
SELECT S.sname FROM Sailors S, Reserves R WHERE
S.sid R.sid AND R.bid 103
Result
DB
Sailors
Reserves