7 7 Multiple-Column Subqueries Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 4 Aggregating Data Using Group Functions.
Advertisements

DatabaseDatabase cs453 Lab8 1 Ins.Ebtesam AL-Etowi.
2 Restricting and Sorting Data Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
Subqueries 11. Objectives After completing this lesson, you should be able to do the following: Describe the types of problems that subqueries can solve.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Copyright  Oracle Corporation, All rights reserved. 6 Subqueries.
5 5 Aggregating Data Using Group Functions Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Aggregating Data Using Group Functions. Objectives After completing this lesson, you should be able to do the following: Identify the available group.
Copyright  Oracle Corporation, All rights reserved. 5 Aggregating Data Using Group Functions.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
6 6 Subqueries Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan (1999), published.
Multiple-Column Subqueries 12. Objectives After completing this lesson, you should be able to do the following: Write a multiple-column subquery Describe.
6-1 Copyright  Oracle Corporation, All rights reserved. Types of Subqueries Single-row subquery Main query Subquery returns CLERK Multiple-row subquery.
Multiple-Column Subqueries. Objectives After completing this lesson, you should be able to do the following: Write a Multiple-column subquery Describe.
Copyright س Oracle Corporation, All rights reserved. 7 Multiple-Column Subqueries.
Copyright  Oracle Corporation, All rights reserved. 7 Multiple-Column Subqueries.
Copyright  Oracle Corporation, All rights reserved. 6 Writing Correlated Subqueries.
18 Copyright © Oracle Corporation, All rights reserved. Advanced Subqueries.
1 Lecture 3: Subqueries DCO11310 Database Systems and Design By Rose Chang.
Introduction to Oracle9i: SQL1 Subqueries. Introduction to Oracle9i: SQL2 Chapter Objectives Determine when it is appropriate to use a subquery Identify.
6 Copyright © 2004, Oracle. All rights reserved. Using Subqueries to Solve Queries.
6 Copyright © Oracle Corporation, All rights reserved. Subqueries.
Chapter 1 Writing Basic SQL Statements Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Logical Operators Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
Ch. 3 Single-Row Functions Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
13 Other Database Objects Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
Subqueries.
Subqueries.
Copyright س Oracle Corporation, All rights reserved. 5 Aggregating Data Using Group Functions.
Joins & Sub-queries. Oracle recognizes that you may want data that resides in multiple tables drawn together in some meaningful way. One of the most important.
6 Copyright © 2004, Oracle. All rights reserved. Using Subqueries to Solve Queries.
7 Multiple-Column Subqueries. 7-2 Objectives At the end of this lesson, you should be able to: Write a multiple-column subquery Describe and explain the.
SQL. Relating Multiple Tables Relational Database Terminology Row PK Column FK Field NULL.
4 Displaying Data from Multiple Tables Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Chapter 12 Subqueries and Merge Statements
Displaying Data from Multiple Tables (SQL99 Syntax with examples)
Review SQL Advanced. Capabilities of SQL SELECT Statements Selection Projection Table 1 Table 2 Table 1 Join.
7 7 Multiple-Column Subqueries Important Legal Notice:  Materials on this lecture are sourced from a book titled “Oracle Education” by Kochhar, Gravina,
Copyright  Oracle Corporation, All rights reserved. 12 Creating Views.
6 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Subqueries.
6 Subqueries. 6-2 Objectives At the end of this lesson, you should be able to: Describe the types of problems that subqueries can solve Define subqueries.
Single-Row Functions. SQL Functions FunctionInput arg 1 arg 2 arg n Function performs action OutputResultvalue.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Chapter 7 Subqueries. Chapter Objectives  Determine when it is appropriate to use a subquery  Identify which clauses can contain subqueries  Distinguish.
Advanced SQL. SQL - Nulls Nulls are not equal to anything - Null is not even equal to Null where columna != ‘ABC’ --this will not return records where.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
6 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Using Subqueries to Solve Queries
Multiple-Column Subqueries
Aggregating Data Using Group Functions
Subqueries.
Subqueries Schedule: Timing Topic 25 minutes Lecture
15 SQL Workshop Important Legal Notice:
Aggregating Data Using Group Functions
Writing Correlated Subqueries
(SQL) Aggregating Data Using Group Functions
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Aggregating Data Using Group Functions
Aggregating Data Using Group Functions
Using Subqueries to Solve Queries
Subqueries Schedule: Timing Topic 25 minutes Lecture
Review SQL Advanced.
Subqueries Schedule: Timing Topic 25 minutes Lecture
Database Programming Using Oracle 11g
Presentation transcript:

7 7 Multiple-Column Subqueries Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan (1999), published by Oracle Corp.  For further information, visit  This presentation must be used for only education purpose for students at Central Washington University which is a member of Oracle Academic Initiatives (OAI) and has used Oracle systems for HRIS & Accounting Systems as a database platform embedded on its PeopleSoft ERP system, since 1999.

Objectives After completing this lesson, you should be able to do the following: Write a multiple-column subquery Describe and explain the behavior of subqueries when null values are retrieved Write a subquery in a FROM clause

Multiple-Column Subqueries Main query MANAGER 10 Subquery SALESMAN30 MANAGER10 CLERK20 Main query compares to Values from a multiple-row and multiple-column subquery MANAGER 10SALESMAN 30 MANAGER 10 CLERK 20

Using Multiple-Column Subqueries Display the order id, product id, and quantity of items in the item table that match both the product id and quantity of an item in order 605. Note: This example applies to a different database from our class database (scott-tiger). SQL> SELECTordid, prodid, qty 2 FROMitem 3 WHERE(prodid, qty) IN ANDordid <> 605; (SELECT prodid, qty FROMitem WHERE ordid = 605)

Using Multiple-Column Subqueries (continued) Display the order number, product number, and quantity of any item in which the product number and quantity match both the product number and quantity of an item in order 605. SQL> SELECTordid, prodid, qty 2 FROMitem 3 WHERE( prodid, qty ) IN ANDordid <> 605; (SELECT prodid, qty FROMitem WHERE ordid = 605

Column Comparisons Pairwise PRODIDQTY Nonpairwise PRODIDQTY

Nonpairwise Comparison Subquery Display the order number, product number, and quantity of any item in which the product number and quantity match any product number and any quantity of an item in Order 605. SQL> SELECTordid, prodid, qty 2 FROMitem 3 WHEREprodid IN ANDqty IN 8 9 ANDordid <> 605; (SELECT prodid, FROMitem WHERE ordid = 605) (SELECT qty FROMitem WHERE ordid = 605)

Nonpairwise Subquery ORDIDPRODIDQTY rows selected.

Null Values in a Subquery SQL> SELECT employee.ename 2 FROM emp employee 3 WHERE employee.empno NOT IN 4 5 no rows selected. (SELECT manager.mgr FROM emp manager);

Using a Subquery in the FROM Clause SQL> SELECTa.ename, a.sal, a.deptno, b.salavg 2 FROM emp a, WHEREa.deptno = b.deptno 6 AND a.sal > b.salavg; (SELECT deptno, avg(sal) salavg FROM emp GROUP BY deptno) b ENAMESALDEPTNOSALAV KING JONES SCOTT rows selected.

Summary A multiple-column subquery returns more than one column. Column comparisons in multiple-column comparisons can be pairwise or nonpairwise. A multiple-column subquery can also be used in the FROM clause of a SELECT statement.