0% found this document useful (0 votes)
40 views

Unit-Ii SQL Queries: Iii Ece A & D, I Sem

This document contains examples of SQL queries. It includes 8 queries that retrieve various pieces of information from Sailors, Reserves, and Boats tables. The queries find names and ages of sailors, sailors with a high rating, sailors who reserved a specific boat, sailors who reserved a red boat, the colors of boats reserved by a sailor, sailors who reserved at least one boat, and ages of sailors with a name matching a pattern.

Uploaded by

Srihari Rao N
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Unit-Ii SQL Queries: Iii Ece A & D, I Sem

This document contains examples of SQL queries. It includes 8 queries that retrieve various pieces of information from Sailors, Reserves, and Boats tables. The queries find names and ages of sailors, sailors with a high rating, sailors who reserved a specific boat, sailors who reserved a red boat, the colors of boats reserved by a sailor, sailors who reserved at least one boat, and ages of sailors with a name matching a pattern.

Uploaded by

Srihari Rao N
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIT-II

SQL Queries

III ECE A & D, I Sem


(Q1) Find the names and ages of all sailors.
SELECT DISTINCT S.sname, S.age FROM
Sailors S;
(Q2) Find all sailors with a rating above 7.
SELECT S.sid, S.sname, S.rating, S.age
FROM Sailors AS S WHERE S.rating > 7;
(Q3) 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;
(OR)
SELECT sname FROM Sailors S, Reserves R
WHERE S.sid = R.sid AND bid=103;
(OR)
SELECT sname FROM Sailors, Reserves
WHERE Sailors.sid = Reserves.sid AND
bid=103;
(Q4) Find the sids of sailors who have reserved a
red boat.
SELECT R.sid FROM Boats B, Reserves R
WHERE B.bid = R.bid AND B.color = ‘red’;
(Q5) Find the names of sailors who have reserved a
red boat.
SELECT S.sname FROM Sailors S, Reserves R,
Boats B WHERE S.sid = R.sid AND R.bid =
B.bid AND B.color = ‘red’;
(Q6) Find the colors of boats reserved by Lubber.
SELECT B.color FROM Sailors S, Reserves R,
Boats B WHERE S.sid = R.sid AND R.bid =
B.bid AND S.sname = ‘Lubber’;
(Q7) Find the names of sailors who have reserved at
least one boat.
SELECT S.sname FROM Sailors S, Reserves R
WHERE S.sid = R.sid;
(Q8) Find the ages of sailors whose name begins
and ends with B and has at least three
characters.
SELECT S.age FROM Sailors S WHERE
S.sname LIKE `B %B’;

You might also like