{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS122aSlides08 - ICS122A EECS116 Introduction to Data...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 ICS122A / EECS116 Introduction to Data Management Spring 2009 Prof. Mike Carey Bren School of ICS UC Irvine Slides based on previous CS122a lecture notes as well as  material borrowed from U-Wisconsin, Stanford, & Berkeley
Image of page 1

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

View Full Document Right Arrow Icon
ICS122A/EECS116 Notes 02 2 Announcements HWs and projects Project Part 1 due today Project Part 2 available online HW #3 due next Tuesday (last one before midterm!) Discussion section meetings Alex will get you going on Project Part 2 tomorrow You should at least have downloaded the RDBMS of your choice and have it with you (to install) on Friday if you want that kind of help Today SQL (cont.)
Image of page 2
ICS122A/EECS116 Notes 08 3 Subqueries Also called nested queries: queries embedded inside an outer query Roughly similar to function calls in programming languages Let’s look at an example: Who’s in Sally’s department? select   E1.ename from     Emp  E1, Emp E2 where   E2.ename = ‘Sally’ AND E1.dno = E2.dno; Or: select  ename from Emp where Emp.dno  in (select dno                              from Emp      subquery where ename = ‘Sally’);   names are scoped Semantics: For each tuple in Emp, evaluate the nested query and check if Emp.dno appears in the set of dno’s returned by nested query. (The nested query returns a table containing dno(s) in which Sally works.)
Image of page 3

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

View Full Document Right Arrow Icon
ICS122A/EECS116 Notes 08 4 Conditions Involving Tables Test for set membership (R is usually a 1-attribute table; varies by vendor) – s IN R   -- s is equal to one of the values in R – s NOT IN R  s is not equal to any of the values in R Set comparison s > ALL R  s is greater than every value in unary relation R s >  SOME  R, s >  ANY  R s is greater than at least 1 element in unary relation R ANY is a synonym of SOME in SQL The usual operators (<, = , >, <=, >=, <>) be used – <> ALL   is equivalent to NOT IN Tests related to empty relations – EXISTS R  -- R is not empty NOT EXISTS
Image of page 4
ICS122A/EECS116 Notes 08 5 Correlated Subqueries The nested query below uses attributes names of E1 (defined in outer query). These two queries are called correlated . Ex : Testing Empty Relations EXISTS checks for a nonempty set Query: Find employees who make more money than some manager SELECT ename       FROM    Emp E1 WHERE EXISTS (SELECT ename  FROM Emp, Dept   WHERE (Emp.ename = Dept.mgr)  AND ( E1 .sal > Emp.sal)); E1: Emp(ename, dno, sal) ename dno sal Jack 111 50K Alice 111 90K Lisa 222 80K Tom 333 70K Mary 333 60K Dept(dno, dname, mgr) dno dname Mgr 111 Sales Alice 222 Toy Lisa 333 Electronics Mary Emp (ename, dno, sal) ename dno sal Jack 111 50K Alice 111 90K Lisa 222 80K Tom 333 70K Mary 333 60K
Image of page 5

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

View Full Document Right Arrow Icon
ICS122A/EECS116 Notes 08 6 Subqueries Producing One Value Sometimes subqueries produce a single value (“scalar subqueries”): SELECT ename FROM Emp WHERE Emp.dno  = (SELECT dno                             
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern