SlideShare uma empresa Scribd logo
1 de 18
Subqueries
Objectives After completing this lesson, you should be able to do the following: Describe the types of problems that subqueries can solve Define subqueries List the types of subqueries Write single-row and multiple-row subqueries
Using a Subquery to Solve a Problem “Who has a salary greater than Jones’?” Main Query “Which employees have a salary greater than Jones’ salary?” ? Subquery ? “What is Jones’ salary?”
Subqueries SELECTselect_list FROMtable WHEREexpr operator 		 	(SELECTselect_list        FROMtable); The subquery (inner query) executes once before the main query. The result of the subquery is used by the main query (outer query).
2975 SQL> SELECT ename 2  FROM   emp 3  WHERE  sal >  4		    (SELECT sal 5               FROM   emp 6               WHERE  empno=7566); Using a Subquery ENAME ---------- KING FORD SCOTT
Guidelines for Using Subqueries Enclose subqueries in parentheses.  Place subqueries on the right side of the comparison operator. Do not add an ORDER BY clause to a subquery. Use single-row operators with single-row subqueries. Use multiple-row operators with multiple-row subqueries.
Main query returns Subquery ,[object Object],Main query CLERK MANAGER returns Subquery ,[object Object],Main query returns CLERK        7900MANAGER  7698 Subquery Types of Subqueries Single-row subquery CLERK
Single-Row Subqueries Return only one row Use single-row comparison operators Operator = >       >=	 <       <=	 <> Meaning Equal to Greater than  Greater than or equal to  Less than  Less than or equal to Not equal to
CLERK 1100 Executing Single-Row Subqueries SQL> SELECT   ename, job2  FROM     emp 3  WHERE    job =  4		(SELECT  job5FROM     emp6WHERE    empno = 7369) 7  AND      sal >  8		(SELECT  sal 9FROMemp 10WHEREempno = 7876);  ENAME      JOB ---------- --------- MILLER     CLERK
Using Group Functions in a Subquery 800 SQL> SELECTename, job, sal 2  FROMemp 3  WHEREsal =  4			(SELECTMIN(sal) 5FROMemp); ENAME      JOB             SAL ---------- --------- --------- SMITH      CLERK           800
HAVING Clause with Subqueries 800 The Oracle Server executes subqueries first. The Oracle Server returns results into the HAVING clause of the main query. SQL> SELECTdeptno, MIN(sal) 2  FROMemp 3  GROUP BYdeptno 4  HAVINGMIN(sal) > 5		(SELECTMIN(sal) 6FROMemp 7WHEREdeptno = 20);
What Is Wrong with This Statement? SQL> SELECT empno, ename 2  FROM   emp 3  WHERE  sal =  4		(SELECT   MIN(sal) 5FROM      emp 6GROUP BY  deptno); Single-row operator with  multiple-row subquery ERROR: ORA-01427: single-row subquery returns more thanone row no rows selected
Will This Statement Work? SQL> SELECT ename, job 2  FROM   emp 3  WHERE  job =  4		(SELECTjob 5FROMemp 6WHEREename='SMYTHE'); no rows selected Subquery returns no values
Multiple-Row Subqueries Return more than one row Use multiple-row comparison operators Operator       IN      ANY      ALL Meaning Equal to any member in the list Compare value to each value returned by the subquery  Compare value to every value returned by the subquery
Using ANY Operator in Multiple-Row Subqueries 1300 1100 800 950 SQL> SELECT  empno, ename, job 2  FROM    emp 3  WHERE   sal < ANY  4			(SELECTsal 5FROMemp 6WHEREjob = 'CLERK') 7  AND    job <> 'CLERK';     EMPNO ENAME      JOB --------- ---------- --------- 7654 MARTIN     SALESMAN  7521 WARD       SALESMAN
Using ALL Operator in Multiple-Row Subqueries 1566.6667 2175 2916.6667 SQL> SELECT  empno, ename, job 2  FROM    emp 3  WHERE   sal > ALL  4		 (SELECTavg(sal) 5FROMemp 6GROUP BYdeptno);     EMPNO ENAME      JOB --------- ---------- --------- 7839 KING       PRESIDENT 7566 JONES      MANAGER 7902 FORD       ANALYST 7788 SCOTT      ANALYST
Summary Subqueries are useful when a query is based on unknown values. SELECTselect_list FROMtable WHEREexpr operator 		 (SELECT select_list FROMtable);
Practice Overview Creating subqueries to query values based on unknown criteria Using subqueries to find out what values exist in one set of data and not in another

Mais conteúdo relacionado

Mais procurados (20)

Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les00 Intoduction
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Les12
Les12Les12
Les12
 
Les01
Les01Les01
Les01
 
Les10
Les10Les10
Les10
 
Les02
Les02Les02
Les02
 
Les09
Les09Les09
Les09
 
SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12
 
Les11
Les11Les11
Les11
 
SQL WORKSHOP::Lecture 5
SQL WORKSHOP::Lecture 5SQL WORKSHOP::Lecture 5
SQL WORKSHOP::Lecture 5
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2
 
MERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsMERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known Facets
 
Les05[1]Aggregating Data Using Group Functions
Les05[1]Aggregating Data  Using Group FunctionsLes05[1]Aggregating Data  Using Group Functions
Les05[1]Aggregating Data Using Group Functions
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02
 
Les08-Oracle
Les08-OracleLes08-Oracle
Les08-Oracle
 
Les06[1]Subqueries
Les06[1]SubqueriesLes06[1]Subqueries
Les06[1]Subqueries
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Data
 

Semelhante a Les06 Subqueries

Les06- Subqueries.ppt
Les06- Subqueries.pptLes06- Subqueries.ppt
Les06- Subqueries.pptgznfrch1
 
Ch 6 Sub Query.pptx
Ch 6 Sub Query.pptxCh 6 Sub Query.pptx
Ch 6 Sub Query.pptxRamishaRauf
 
SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6Umair Amjad
 
Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sqlSushil Mishra
 
Les07[1]Multiple-Column Subqueries
Les07[1]Multiple-Column SubqueriesLes07[1]Multiple-Column Subqueries
Les07[1]Multiple-Column Subqueriessiavosh kaviani
 
Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)Achmad Solichin
 
Restricting and sorting data
Restricting and sorting data Restricting and sorting data
Restricting and sorting data HuzaifaMushtaq3
 
Subqueries -Oracle DataBase
Subqueries -Oracle DataBaseSubqueries -Oracle DataBase
Subqueries -Oracle DataBaseSalman Memon
 
Mysqlppt
MysqlpptMysqlppt
MysqlpptReka
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Finalmukesh24pandey
 

Semelhante a Les06 Subqueries (20)

Les06- Subqueries.ppt
Les06- Subqueries.pptLes06- Subqueries.ppt
Les06- Subqueries.ppt
 
7992267.ppt
7992267.ppt7992267.ppt
7992267.ppt
 
Ch 6 Sub Query.pptx
Ch 6 Sub Query.pptxCh 6 Sub Query.pptx
Ch 6 Sub Query.pptx
 
Lab5 sub query
Lab5   sub queryLab5   sub query
Lab5 sub query
 
Week6_Theory.pptx
Week6_Theory.pptxWeek6_Theory.pptx
Week6_Theory.pptx
 
SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6
 
Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sql
 
Les06
Les06Les06
Les06
 
Les12[1]Creating Views
Les12[1]Creating ViewsLes12[1]Creating Views
Les12[1]Creating Views
 
Les06
Les06Les06
Les06
 
Les07[1]Multiple-Column Subqueries
Les07[1]Multiple-Column SubqueriesLes07[1]Multiple-Column Subqueries
Les07[1]Multiple-Column Subqueries
 
Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)
 
Restricting and sorting data
Restricting and sorting data Restricting and sorting data
Restricting and sorting data
 
chap2 (3).ppt
chap2 (3).pptchap2 (3).ppt
chap2 (3).ppt
 
Les02.pptx
Les02.pptxLes02.pptx
Les02.pptx
 
Sql2
Sql2Sql2
Sql2
 
Subqueries -Oracle DataBase
Subqueries -Oracle DataBaseSubqueries -Oracle DataBase
Subqueries -Oracle DataBase
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 

Último

char Dham yatra, Uttarakhand tourism.pptx
char Dham yatra, Uttarakhand tourism.pptxchar Dham yatra, Uttarakhand tourism.pptx
char Dham yatra, Uttarakhand tourism.pptxpalakdigital7
 
08448380779 Call Girls In Shahdara Women Seeking Men
08448380779 Call Girls In Shahdara Women Seeking Men08448380779 Call Girls In Shahdara Women Seeking Men
08448380779 Call Girls In Shahdara Women Seeking MenDelhi Call girls
 
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...Apsara Of India
 
best weekend places near delhi where you should visit.pdf
best weekend places near delhi where you should visit.pdfbest weekend places near delhi where you should visit.pdf
best weekend places near delhi where you should visit.pdftour guide
 
visa consultant | 📞📞 03094429236 || Best Study Visa Consultant
visa consultant | 📞📞 03094429236 || Best Study Visa Consultantvisa consultant | 📞📞 03094429236 || Best Study Visa Consultant
visa consultant | 📞📞 03094429236 || Best Study Visa ConsultantSherazi Tours
 
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday SafarisKibera Holiday Safaris Safaris
 
💕📲09602870969💓Girl Escort Services Udaipur Call Girls in Chittorgarh Haldighati
💕📲09602870969💓Girl Escort Services Udaipur Call Girls in Chittorgarh Haldighati💕📲09602870969💓Girl Escort Services Udaipur Call Girls in Chittorgarh Haldighati
💕📲09602870969💓Girl Escort Services Udaipur Call Girls in Chittorgarh HaldighatiApsara Of India
 
DARK TRAVEL AGENCY presented by Khuda Bux
DARK TRAVEL AGENCY presented by Khuda BuxDARK TRAVEL AGENCY presented by Khuda Bux
DARK TRAVEL AGENCY presented by Khuda BuxBeEducate
 
Genesis 1:6 || Meditate the Scripture daily verse by verse
Genesis 1:6  ||  Meditate the Scripture daily verse by verseGenesis 1:6  ||  Meditate the Scripture daily verse by verse
Genesis 1:6 || Meditate the Scripture daily verse by versemaricelcanoynuay
 
How to Get Unpublished Flight Deals and Discounts?
How to Get Unpublished Flight Deals and Discounts?How to Get Unpublished Flight Deals and Discounts?
How to Get Unpublished Flight Deals and Discounts?FlyFairTravels
 
Top 10 Traditional Indian Handicrafts.pptx
Top 10 Traditional Indian Handicrafts.pptxTop 10 Traditional Indian Handicrafts.pptx
Top 10 Traditional Indian Handicrafts.pptxdishha99
 
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779Delhi Call girls
 
Study Consultants in Lahore || 📞03094429236
Study Consultants in Lahore || 📞03094429236Study Consultants in Lahore || 📞03094429236
Study Consultants in Lahore || 📞03094429236Sherazi Tours
 
08448380779 Call Girls In Chirag Enclave Women Seeking Men
08448380779 Call Girls In Chirag Enclave Women Seeking Men08448380779 Call Girls In Chirag Enclave Women Seeking Men
08448380779 Call Girls In Chirag Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Bhikaji Cama Palace Women Seeking Men
08448380779 Call Girls In Bhikaji Cama Palace Women Seeking Men08448380779 Call Girls In Bhikaji Cama Palace Women Seeking Men
08448380779 Call Girls In Bhikaji Cama Palace Women Seeking MenDelhi Call girls
 
BERMUDA Triangle the mystery of life.pptx
BERMUDA Triangle the mystery of life.pptxBERMUDA Triangle the mystery of life.pptx
BERMUDA Triangle the mystery of life.pptxseribangash
 

Último (20)

char Dham yatra, Uttarakhand tourism.pptx
char Dham yatra, Uttarakhand tourism.pptxchar Dham yatra, Uttarakhand tourism.pptx
char Dham yatra, Uttarakhand tourism.pptx
 
08448380779 Call Girls In Shahdara Women Seeking Men
08448380779 Call Girls In Shahdara Women Seeking Men08448380779 Call Girls In Shahdara Women Seeking Men
08448380779 Call Girls In Shahdara Women Seeking Men
 
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
 
best weekend places near delhi where you should visit.pdf
best weekend places near delhi where you should visit.pdfbest weekend places near delhi where you should visit.pdf
best weekend places near delhi where you should visit.pdf
 
visa consultant | 📞📞 03094429236 || Best Study Visa Consultant
visa consultant | 📞📞 03094429236 || Best Study Visa Consultantvisa consultant | 📞📞 03094429236 || Best Study Visa Consultant
visa consultant | 📞📞 03094429236 || Best Study Visa Consultant
 
Call Girls In Munirka 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Munirka 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In Munirka 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Munirka 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
 
💕📲09602870969💓Girl Escort Services Udaipur Call Girls in Chittorgarh Haldighati
💕📲09602870969💓Girl Escort Services Udaipur Call Girls in Chittorgarh Haldighati💕📲09602870969💓Girl Escort Services Udaipur Call Girls in Chittorgarh Haldighati
💕📲09602870969💓Girl Escort Services Udaipur Call Girls in Chittorgarh Haldighati
 
DARK TRAVEL AGENCY presented by Khuda Bux
DARK TRAVEL AGENCY presented by Khuda BuxDARK TRAVEL AGENCY presented by Khuda Bux
DARK TRAVEL AGENCY presented by Khuda Bux
 
Genesis 1:6 || Meditate the Scripture daily verse by verse
Genesis 1:6  ||  Meditate the Scripture daily verse by verseGenesis 1:6  ||  Meditate the Scripture daily verse by verse
Genesis 1:6 || Meditate the Scripture daily verse by verse
 
How to Get Unpublished Flight Deals and Discounts?
How to Get Unpublished Flight Deals and Discounts?How to Get Unpublished Flight Deals and Discounts?
How to Get Unpublished Flight Deals and Discounts?
 
Rohini Sector 18 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 18 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 18 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 18 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Top 10 Traditional Indian Handicrafts.pptx
Top 10 Traditional Indian Handicrafts.pptxTop 10 Traditional Indian Handicrafts.pptx
Top 10 Traditional Indian Handicrafts.pptx
 
Call Girls Service !! Indirapuram!! @9999965857 Delhi 🫦 No Advance VVVIP 🍎 S...
Call Girls Service !! Indirapuram!! @9999965857 Delhi 🫦 No Advance  VVVIP 🍎 S...Call Girls Service !! Indirapuram!! @9999965857 Delhi 🫦 No Advance  VVVIP 🍎 S...
Call Girls Service !! Indirapuram!! @9999965857 Delhi 🫦 No Advance VVVIP 🍎 S...
 
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
 
Study Consultants in Lahore || 📞03094429236
Study Consultants in Lahore || 📞03094429236Study Consultants in Lahore || 📞03094429236
Study Consultants in Lahore || 📞03094429236
 
08448380779 Call Girls In Chirag Enclave Women Seeking Men
08448380779 Call Girls In Chirag Enclave Women Seeking Men08448380779 Call Girls In Chirag Enclave Women Seeking Men
08448380779 Call Girls In Chirag Enclave Women Seeking Men
 
08448380779 Call Girls In Bhikaji Cama Palace Women Seeking Men
08448380779 Call Girls In Bhikaji Cama Palace Women Seeking Men08448380779 Call Girls In Bhikaji Cama Palace Women Seeking Men
08448380779 Call Girls In Bhikaji Cama Palace Women Seeking Men
 
Call Girls Service !! New Friends Colony!! @9999965857 Delhi 🫦 No Advance VV...
Call Girls Service !! New Friends Colony!! @9999965857 Delhi 🫦 No Advance  VV...Call Girls Service !! New Friends Colony!! @9999965857 Delhi 🫦 No Advance  VV...
Call Girls Service !! New Friends Colony!! @9999965857 Delhi 🫦 No Advance VV...
 
BERMUDA Triangle the mystery of life.pptx
BERMUDA Triangle the mystery of life.pptxBERMUDA Triangle the mystery of life.pptx
BERMUDA Triangle the mystery of life.pptx
 

Les06 Subqueries

  • 2. Objectives After completing this lesson, you should be able to do the following: Describe the types of problems that subqueries can solve Define subqueries List the types of subqueries Write single-row and multiple-row subqueries
  • 3. Using a Subquery to Solve a Problem “Who has a salary greater than Jones’?” Main Query “Which employees have a salary greater than Jones’ salary?” ? Subquery ? “What is Jones’ salary?”
  • 4. Subqueries SELECTselect_list FROMtable WHEREexpr operator (SELECTselect_list FROMtable); The subquery (inner query) executes once before the main query. The result of the subquery is used by the main query (outer query).
  • 5. 2975 SQL> SELECT ename 2 FROM emp 3 WHERE sal > 4 (SELECT sal 5 FROM emp 6 WHERE empno=7566); Using a Subquery ENAME ---------- KING FORD SCOTT
  • 6. Guidelines for Using Subqueries Enclose subqueries in parentheses. Place subqueries on the right side of the comparison operator. Do not add an ORDER BY clause to a subquery. Use single-row operators with single-row subqueries. Use multiple-row operators with multiple-row subqueries.
  • 7.
  • 8. Single-Row Subqueries Return only one row Use single-row comparison operators Operator = > >= < <= <> Meaning Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to
  • 9. CLERK 1100 Executing Single-Row Subqueries SQL> SELECT ename, job2 FROM emp 3 WHERE job = 4 (SELECT job5FROM emp6WHERE empno = 7369) 7 AND sal > 8 (SELECT sal 9FROMemp 10WHEREempno = 7876); ENAME JOB ---------- --------- MILLER CLERK
  • 10. Using Group Functions in a Subquery 800 SQL> SELECTename, job, sal 2 FROMemp 3 WHEREsal = 4 (SELECTMIN(sal) 5FROMemp); ENAME JOB SAL ---------- --------- --------- SMITH CLERK 800
  • 11. HAVING Clause with Subqueries 800 The Oracle Server executes subqueries first. The Oracle Server returns results into the HAVING clause of the main query. SQL> SELECTdeptno, MIN(sal) 2 FROMemp 3 GROUP BYdeptno 4 HAVINGMIN(sal) > 5 (SELECTMIN(sal) 6FROMemp 7WHEREdeptno = 20);
  • 12. What Is Wrong with This Statement? SQL> SELECT empno, ename 2 FROM emp 3 WHERE sal = 4 (SELECT MIN(sal) 5FROM emp 6GROUP BY deptno); Single-row operator with multiple-row subquery ERROR: ORA-01427: single-row subquery returns more thanone row no rows selected
  • 13. Will This Statement Work? SQL> SELECT ename, job 2 FROM emp 3 WHERE job = 4 (SELECTjob 5FROMemp 6WHEREename='SMYTHE'); no rows selected Subquery returns no values
  • 14. Multiple-Row Subqueries Return more than one row Use multiple-row comparison operators Operator IN ANY ALL Meaning Equal to any member in the list Compare value to each value returned by the subquery Compare value to every value returned by the subquery
  • 15. Using ANY Operator in Multiple-Row Subqueries 1300 1100 800 950 SQL> SELECT empno, ename, job 2 FROM emp 3 WHERE sal < ANY 4 (SELECTsal 5FROMemp 6WHEREjob = 'CLERK') 7 AND job <> 'CLERK'; EMPNO ENAME JOB --------- ---------- --------- 7654 MARTIN SALESMAN 7521 WARD SALESMAN
  • 16. Using ALL Operator in Multiple-Row Subqueries 1566.6667 2175 2916.6667 SQL> SELECT empno, ename, job 2 FROM emp 3 WHERE sal > ALL 4 (SELECTavg(sal) 5FROMemp 6GROUP BYdeptno); EMPNO ENAME JOB --------- ---------- --------- 7839 KING PRESIDENT 7566 JONES MANAGER 7902 FORD ANALYST 7788 SCOTT ANALYST
  • 17. Summary Subqueries are useful when a query is based on unknown values. SELECTselect_list FROMtable WHEREexpr operator (SELECT select_list FROMtable);
  • 18. Practice Overview Creating subqueries to query values based on unknown criteria Using subqueries to find out what values exist in one set of data and not in another