170 likes | 321 Views
SELECT Statement. Chapter (7): Advanced SQL. Find names of sailors who’ve reserved boat # 103. Sailors. Reserves. SELECT sname FROM Sailors, Reserves WHERE Sailors.sid = Reserves.sid AND bid=103. Find names of sailors who’ve reserved boat # 103. Sailors. Reserves.
E N D
SELECT Statement Chapter (7): Advanced SQL
Find names of sailors who’ve reserved boat #103 Sailors Reserves SELECT sname FROM Sailors, Reserves WHERE Sailors.sid=Reserves.sid AND bid=103
Find names of sailors who’ve reserved boat #103 Sailors Reserves SELECT S.sname FROM Sailors S, Reserves R WHERE S.sid=R.sid AND bid=103
CROSS JOIN Sailors Reserves SELECT * FROM Sailors S, Reserves R SELECT * FROM Sailors S CROSS JOINReserves R
INNER-JOIN Sailors Reserves SELECT * FROM Sailors S, Reserves R WHERE S.sid=R.sid SELECT * FROM Sailors S INNER JOINReserves R ON S.sid=R.sid SELECT * FROM Sailors S INNER JOINReserves R USING sid
EQUI-JOIN Reserves Sailors SELECT * FROM Sailors S, Reserves R WHERE S.sid=R.sid SELECT * FROM Sailors S INNER JOINReserves R ON S.sid=R.sid SELECT * FROM Sailors S INNER JOINReserves R USING sid
NATURAL-JOIN SELECT * FROM Sailors S INNER JOINReserves R USING sid SELECT * FROM Sailors S NATURAL JOINReserves R USING sid
LEFTOUTER-JOIN Report all the sailors with their reservations SELECT * FROM Sailors S, Reserves R WHERE S.sid=R.sid SELECT * FROM Sailors S LEFT OUTER JOINReserves R WHERE S.sid=R.sid
LEFTOUTER-JOIN Report all the sailors with their reservations SELECT * FROM Sailors S, Reserves R WHERE S.sid=R.sid SELECT * FROM Sailors S NATURAL LEFT OUTER JOINReserves R WHERE S.sid=R.sid
RIGHT OUTER-JOIN Report all the boats with their reservations Reserves Boats SELECT * FROM Reserves R RIGHT OUTER-JOINBoats B WHERE R.bid=B.bid
Find sailors’ names who’ve reserved at least one boat Reserves Sailors SELECTDISTINCT S.sname FROM Sailors S, Reserves R WHERES.sid=R.sid
Find names of sailors who’ve reserved a redor a green boat SELECTS.sname FROM Sailors S, Reserves R, Boats B WHERE S.sid=R.sid ANDR.bid=B.bid AND(B.color=‘red’ ORB.color=‘green’) SELECTS.sname FROM Sailors S, Boats B, Reserves R WHERE S.sid=R.sid AND R.bid=B.bid ANDB.color=‘red’ UNION SELECTS.sname FROM Sailors S, Boats B, Reserves R WHERE S.sid=R.sid ANDR.bid=B.bidANDB.color=‘green’
Find names of sailors who’ve reserved a redanda green boat SELECTS.sname FROM Sailors S, Reserves R, Boats B WHERE S.sid=R.sid ANDR.bid=B.bid AND(B.color=‘red’ AND B.color=‘green’) SELECTS.sname FROM Sailors S, Reserves R, Boats B WHERE S.sid=R.sid AND R.bid=B.bid ANDB.color=‘red’ INTERSECT SELECTS.sname FROM Sailors S, Reserves R, Boats B WHERE S.sid=R.sid ANDR.bid=B.bidANDB.color=‘green’
Find names of sailors who’ve reserved a redanda green boat SELECTS.sid FROM Sailors S, Boats B, Reserves R WHERES.sid=R.sidANDR.bid=B.bidANDB.color=‘red’ ANDS.sidIN (SELECT S2.sid FROM Sailors S2, Boats B2, Reserves R2 WHERE S2.sid=R2.sid AND R2.bid=B2.bid AND B2.color=‘green’) SELECTS.sname FROM Sailors S, Reserves R, Boats B WHERE S.sid=R.sid AND R.bid=B.bid ANDB.color=‘red’ INTERSECT SELECTS.sname FROM Sailors S, Reserves R, Boats B WHERE S.sid=R.sid ANDR.bid=B.bidANDB.color=‘green’
Find names of sailors who’ve reserved a redand nota green boat SELECTS.sid FROM Sailors S, Boats B, Reserves R WHERES.sid=R.sidANDR.bid=B.bidANDB.color=‘red’ ANDS.sidNOT IN(SELECT S2.sid FROM Sailors S2, Boats B2, Reserves R2 WHERE S2.sid=R2.sid AND R2.bid=B2.bid AND B2.color=‘green’) SELECTS.sname FROM Sailors S, Reserves R, Boats B WHERE S.sid=R.sid AND R.bid=B.bid ANDB.color=‘red’ EXCEPT SELECTS.sname FROM Sailors S, Reserves R, Boats B WHERE S.sid=R.sid ANDR.bid=B.bidANDB.color=‘green’
VIEW CREATE VIEW Emp_Manager AS SELECT* FROMEmp_Manager SELECTMANAGER FROMEmp_Manager SELECTMANAGER FROMEmp_Manager WHERE EMPLOYEEID = 123 Security …