Subqueries.

Slides:



Advertisements
Similar presentations
2 Copyright © 2007, Oracle. All rights reserved. Restricting and Sorting Data.
Advertisements

DatabaseDatabase cs453 Lab8 1 Ins.Ebtesam AL-Etowi.
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. 6 Subqueries.
Database Programming Sections 5 & 6 – Group functions, COUNT, DISTINCT, NVL, GROUP BY, HAVING clauses, Subqueries.
DATABASE PROGRAMMING Sections 5-7. Write a query that shows the average, maximum, and minimum salaries for all employees with jobs in the programming.
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.
7 7 Multiple-Column Subqueries Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
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.
CSEN 5314 Quiz What type of join is needed when you wish to include rows that do not have matching values? A. Equi-joinB. Natural join C. Outer.
6 Copyright © 2004, Oracle. All rights reserved. Using Subqueries to Solve Queries.
6 Copyright © Oracle Corporation, All rights reserved. Subqueries.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Functions Oracle Labs 5 & 6. 2/3/2005Adapted from Introduction to Oracle: SQL and PL/SQL 2 SQL Functions Function arg n arg 2 arg 1. Input Resulting Value.
SQL advanced select using Oracle 1 7. Multiple Tables: Joins and Set Operations 8. Subqueries: Nested Queries.
Copyright © 2004, Oracle. All rights reserved. Lecture 6 Displaying Data from Multiple Tables ORACLE.
Database Programming Sections 6 –Subqueries, Single Row Subqueries, Multiple-column subqueries, Multiple-row Subqueries, Correlated Subqueries 11/2/10,
Displaying Data from Multiple Tables (Join). EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS.
Subqueries.
Subqueries.
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.
Copyright © 2004, Oracle. All rights reserved. U SING S UBQUERIES TO S OLVE Q UERIES.
5 Copyright © Oracle Corporation, All rights reserved. Aggregating Data Using Group Functions.
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.
Unit 4 Queries and Joins. Key Concepts Using the SELECT statement Statement clauses Subqueries Multiple table statements Using table pseudonyms Inner.
Join, Subqueries and set operators. Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … …
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
SQL advanced select using Oracle 1. 2 Select Simple –data from a single table Advanced –data from more tables join sub-queries.
Chapter 12 Subqueries and Merge Statements
7 7 Multiple-Column Subqueries Important Legal Notice:  Materials on this lecture are sourced from a book titled “Oracle Education” by Kochhar, Gravina,
6 Copyright © Oracle Corporation, All rights reserved. Subqueries.
IFS180 Intro. to Data Management Chapter 11 - Subqueries.
6 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using 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.
SQL advanced select using Oracle 1 Multiple Tables: Joins and Set Operations Subqueries: Nested Queries.
Database Programming Sections 6 –Subqueries, Single Row Subqueries, Multiple-row Subqueries, Correlated Subqueries.
Chapter 7 Subqueries. Chapter Objectives  Determine when it is appropriate to use a subquery  Identify which clauses can contain subqueries  Distinguish.
1 Introduction to Database Systems, CS420 SQL JOIN, Group-by and Sub-query Clauses.
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.
6 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Using Subqueries to Solve Queries
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Chapter 1 Introduction.
Comparison Operators Relational Operators.
Subqueries.
Subqueries Schedule: Timing Topic 25 minutes Lecture
Using Subqueries to Solve Queries
Interacting with the Oracle Server
Writing Correlated Subqueries
Using the Set Operators
Chapter 1 Introduction.
Using Subqueries to Solve Queries
SQL Subquery.
Chapter 1 Introduction.
Subqueries Schedule: Timing Topic 25 minutes Lecture
Using Subqueries to Solve Queries
Subqueries.
Using Subqueries to Solve Queries
Subqueries Schedule: Timing Topic 25 minutes Lecture
Subqueries Schedule: Timing Topic 25 minutes Lecture
Presentation transcript:

Subqueries

Based on Introduction to Oracle: SQL and PL/SQL Problem Solution to question Requires a two step query Can use only one SQL statement Example – Who has a salary greater than Jones’ salary? 2/24/05 Based on Introduction to Oracle: SQL and PL/SQL

Based on Introduction to Oracle: SQL and PL/SQL Use a Subquery Main Query Which employees have a salary greater than Jones’ salary? Subquery What is Jones’ salary? 2/24/05 Based on Introduction to Oracle: SQL and PL/SQL

Based on Introduction to Oracle: SQL and PL/SQL SELECT select_list FROM table WHERE expr operator (SELECT select_list FROM table) Subquery (bottom) executed first Outer query (top) executed last Addition SQL clauses can be added Inner & Outer queries 2/24/05 Based on Introduction to Oracle: SQL and PL/SQL

Based on Introduction to Oracle: SQL and PL/SQL Types of Subqueries Single-row subquery Multiple-row subquery Multiple-column subquery Main query Subquery CLERK Main query returns CLERK MANAGER Subquery Main query returns Subquery CLERK 7900 MANAGER 7698 2/24/05 Based on Introduction to Oracle: SQL and PL/SQL

Single-Row Subqueries Return only one row to Main Query Use single-row comparison operators =, >, >=, <, <=, and <> 2/24/05 Based on Introduction to Oracle: SQL and PL/SQL

Based on Introduction to Oracle: SQL and PL/SQL Example Find the employee names and jobs for employees whose salary is greater than employee number 7876 and who have the same job as employee number 7369. 2/24/05 Based on Introduction to Oracle: SQL and PL/SQL

Multiple-Row Subqueries Return more than one row Use multiple-row comparison operators IN, equal to any member in the list ANY ALL 2/24/05 Based on Introduction to Oracle: SQL and PL/SQL

Based on Introduction to Oracle: SQL and PL/SQL Example Find the employee name, salary, and department number for the employee who has the minimum salary in each department. 2/24/05 Based on Introduction to Oracle: SQL and PL/SQL