Chap8

Chap8 - Chapter 8:Advanced SQL DML(Multiple Tables Jinie...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 8:Advanced SQL DML (Multiple Tables) Jinie Pak Department of Information Systems UMBC Review Last class, we covered DML operations in a single table In the real world, you hardly work with a single table Learning Objectives Use the following SQL commands to manipulate multiple tables: UNION, DIFFERENCE, INTERSECT JOIN Learn the basics of nested query Use IN and EXISTS to perform nested queries Understand the difference between correlated and uncorrelated queries CASE: Video Shop CID CNAME CITY C1 C2 C3 C4 C5 Smith Jones Blake Clark Adams London Paris Paris London Athens FID FNAME PRICE F1 F2 F3 F4 F5 F6 Jurassic Park III The Others Senseless Dragon Heart 007 America Sweetheart 2.99 3.55 5.99 6.00 5.00 0.59 TYPE Action Horror Comedy Drama Action Comedy CID C1 C1 C1 C1 C1 C1 C2 C2 C3 C4 C4 C4 FID F1 F2 F3 F4 F5 F6 F1 F2 F2 F2 F4 F5 Date 1/3 10/2 9/4 1/2 1/1 8/1 1/3 1/4 12/2 1/2 1/3 11/4 FILM CUSTOMER RENT DML: PRODUCT Product: SQL SELECT * FROM A,B A B C 1 y $ 2 x % 3 y & D E “Tom” 3 “Eric” 1 X A B C D E 1 y $ “Tom” 3 2 x % “Tom” 3 3 y & “Tom” 3 1 y $ “Eric” 1 2 x % “Eric” 1 3 y & “Eric” 1 Table A Table B DML: JOIN Equal Join SQL SELECT * FROM A,B WHERE A.a = B.e A B C 1 y $ 2 x % 3 y & D E “Tom” 3 “Eric” 1 X Table A Table B A B C D E 1 y $ “Tom” 3 2 x % “Tom” 3 3 y & “Tom” 3 1 y $ “Eric” 1 2 x % “Eric” 1 3 y & “Eric” 1 DML: JOIN Join (Natural Join) SQL SELECT A.a, A.b, A.c, B.d FROM A,B WHERE A.a = B.e A B C 1 y $ 2 x % 3 y & D E “Tom” 3 “Eric” 1 X A B C D Table A Table B 3 y & “Tom” 1 y $ “Eric” JOIN: SELECT Q 1. List info. about customers who rented F1 before SQL: SELECT * FROM CUSTOMER, RENT WHERE CID = CID AND FID = ‘F1’; ERROR at line 3: ORA-00918: column ambiguously defined JOIN: SELECT SQL: SELECT * FROM CUSTOMER, RENT WHERE CID = CID AND FID = ‘F1’; Attributes names must be qualified when confusion rises Whose attributes? Whose attributes? JOIN: SELECT SQL: SELECT CUSTOMER.* FROM CUSTOMER, RENT WHERE CUSTOMER.CID = RENT.CID AND FID = ‘F1’; Do we need to specify FID? Practice: JOIN Q2. List name of films that were rented before Oct. 2009 SQL: FNAME-------------------- Beautiful Mind Pay it forward Chicken Run Beautiful Mind Green Miles Green Miles Green Miles E.T. Pay it forward Practice: JOIN Q2. List name of films that were rented before Oct. 2009 SQL: SELECT FILM.FNAME FROM FILM, RENT WHERE FILM.fid = RENT.fid AND rent_day < ‘1-OCT-2009’; FNAME-------------------- Beautiful Mind Pay it forward Chicken Run Beautiful Mind Green Miles Green Miles Green Miles E.T....
View Full Document

Page1 / 49

Chap8 - Chapter 8:Advanced SQL DML(Multiple Tables Jinie...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online