Introduction to Oracle9i: SQL1 Subqueries. Introduction to Oracle9i: SQL2 Chapter Objectives Determine when it is appropriate to use a subquery Identify.

Slides:



Advertisements
Similar presentations
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
Advertisements

Chapter 4 Joining Multiple Tables
A Guide to SQL, Seventh Edition. Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables.
Chapter 7 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 12 Subqueries and Merge Statements (up to p.451) Jason C. H. Chen, Ph.D. Professor of MIS School of.
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.
Chapter 11 Group Functions
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.
1 Lecture 3: Subqueries DCO11310 Database Systems and Design By Rose Chang.
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
6 Copyright © 2004, Oracle. All rights reserved. Using Subqueries to Solve Queries.
6 Copyright © Oracle Corporation, All rights reserved. Subqueries.
Introduction to Oracle9i: SQL1 SQL Group Functions.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
Database Systems More SQL Database Design -- More SQL1.
Introduction to Oracle9i: SQL1 Views. Introduction to Oracle9i: SQL2 Chapter Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
Chapter 6 Group Functions. Chapter Objectives  Differentiate between single-row and multiple-row functions  Use the SUM and AVG functions for numeric.
Chapter 3 Single-Table Queries
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Chapter 5 Selected Single-Row Functions. Chapter Objectives  Use the UPPER, LOWER, and INITCAP functions to change the case of field values and character.
SQL advanced select using Oracle 1 7. Multiple Tables: Joins and Set Operations 8. Subqueries: Nested Queries.
A Guide to MySQL 5. 2 Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables Use a subquery.
Database Programming Sections 6 –Subqueries, Single Row Subqueries, Multiple-column subqueries, Multiple-row Subqueries, Correlated Subqueries 11/2/10,
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Subqueries.
Subqueries.
5 Copyright © Oracle Corporation, All rights reserved. Aggregating Data Using Group Functions.
6 Copyright © 2004, Oracle. All rights reserved. Using Subqueries to Solve Queries.
Chapter 4 Multiple-Table Queries
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
Join, Subqueries and set operators. Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … …
1 Multiple Table Queries. 2 Objectives  Retrieve data from more than one table by joining tables  Using IN and EXISTS to query multiple tables  Nested.
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
Hassan Tariq MULTIPLE TABLES: SQL provides a convenient operation to retrieve information from multiple tables.SQL provides a convenient operation to.
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
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.
In this session, you will learn to: Query data by using joins Query data by using subqueries Objectives.
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.
Slide 1 of 32ASH-Training Querying and Managing Data Using SQL Server 2014 By: Segla In this session, you will learn to: Query data by using joins Query.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
Chapter 11 – Data Manipulation: Relational Algebra and SQL1 Unit 9: Data Manipulation: Relational Algebra and SQL IT238: Data Modeling and Database Design.
IFS180 Intro. to Data Management Chapter 10 - Unions.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Using Subqueries to Solve Queries
More SQL: Complex Queries,
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Subqueries Schedule: Timing Topic 25 minutes Lecture
Using Subqueries to Solve Queries
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Using Subqueries to Solve Queries
SQL Subquery.
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:

Introduction to Oracle9i: SQL1 Subqueries

Introduction to Oracle9i: SQL2 Chapter Objectives Determine when it is appropriate to use a subquery Identify which clauses can contain subqueries Distinguish between an outer query and a subquery Use a single-row subquery in a WHERE clause Use a single-row subquery in a HAVING clause Use a single-row subquery in a SELECT clause

Introduction to Oracle9i: SQL3 Chapter Objectives Distinguish between single-row and multiple- row comparison operators Use a multiple-row subquery in a WHERE clause Use a multiple-row subquery in a HAVING clause Use a multiple-column subquery in a WHERE clause

Introduction to Oracle9i: SQL4 Chapter Objectives Create an inline view using a multiple- column subquery in a FROM clause Compensate for NULL values in subqueries Distinguish between correlated and uncorrelated subqueries Nest a subquery inside another subquery

Introduction to Oracle9i: SQL5 Subquery Used when query is based on unknown value A query nested inside another query Requires SELECT and FROM clauses Must be enclosed in parentheses Place on right side of comparison operator

Introduction to Oracle9i: SQL6 Types of Subqueries

Introduction to Oracle9i: SQL7 Single-Row Subquery Operators Can only return one result to outer query Operators include =, >, =,

Introduction to Oracle9i: SQL8 Single-Row Subquery – In WHERE Clause Used for comparison against individual data

Introduction to Oracle9i: SQL9 Single-Row Subquery – In HAVING Clause Required when returned value is compared to grouped data

Introduction to Oracle9i: SQL10 Single-Row Subquery – In SELECT Clause Replicates subquery value for each row displayed

Introduction to Oracle9i: SQL11 Multiple - Row Subqueries Return more than one row of results Require use of IN, ANY, ALL, or EXISTS operators

Introduction to Oracle9i: SQL12 ANY and ALL Operators Combine with arithmetic operators

Introduction to Oracle9i: SQL13 EXISTS Operator Determines whether condition exists in subquery

Introduction to Oracle9i: SQL14 Multiple-Row Subquery – In WHERE Clause

Introduction to Oracle9i: SQL15 Multiple-Row Subquery – In HAVING Clause

Introduction to Oracle9i: SQL16 Multiple-Column Subquery Returns more than one column in results Can return more than one row Column list on left side of operator must be in parentheses Uses IN operator for WHERE and HAVING clauses

Introduction to Oracle9i: SQL17 Multiple-Column Subquery – In FROM Clause Creates temporary table

Introduction to Oracle9i: SQL18 Multiple-Column Subquery – In WHERE Clause Returns multiple columns for evaluation

Introduction to Oracle9i: SQL19 NULL Values When subquery might return NULL values, use NVL function

Introduction to Oracle9i: SQL20 Uncorrelated Subqueries Processing sequence: –Inner query executed first –Result passed to outer query –Outer query executed

Introduction to Oracle9i: SQL21 Correlated Subqueries Inner query executed once for each row processed by outer query Inner query references row contained in outer query

Introduction to Oracle9i: SQL22 Nested Subqueries Maximum 255 subqueries if nested in WHERE clause No limit if nested in FROM clause Innermost subquery resolved first, then next level, etc.

Introduction to Oracle9i: SQL23 Nested Subquery Example Innermost resolved first (3), then second level (2), then outer query (1)