CS122aSlides08

CS122aSlides08 - ICS122A / EECS116 Introduction to Data...

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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.)
Background 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.)
Background image of page 3

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

View Full DocumentRight 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
Background 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
Background image of page 5

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

View Full DocumentRight Arrow Icon
ICS122A/EECS116 Notes 08 6 Subqueries Producing One Value Sometimes subqueries produce a single value (“scalar subqueries”):
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/18/2009 for the course CS 122a taught by Professor Carey during the Spring '09 term at UC Irvine.

Page1 / 27

CS122aSlides08 - ICS122A / EECS116 Introduction to Data...

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

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