1 / 23

Chapter 7 Subqueries

Chapter 7 Subqueries. 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

dick
Télécharger la présentation

Chapter 7 Subqueries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 7Subqueries Oracle9i: SQL

  2. 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 Oracle9i: SQL

  3. 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 Oracle9i: SQL

  4. 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 Oracle9i: SQL

  5. 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 Oracle9i: SQL

  6. Types of Subqueries Oracle9i: SQL

  7. Single-Row Subquery Operators • Can only return one result to outer query • Operators include =, >, <, >=, <=, < > Oracle9i: SQL

  8. Single-Row Subquery – In WHERE Clause Used for comparison against individual data Oracle9i: SQL

  9. Single-Row Subquery – In HAVING Clause Required when returned value is compared to grouped data Oracle9i: SQL

  10. Single-Row Subquery – In SELECT Clause Replicates subquery value for each row displayed Oracle9i: SQL

  11. Multiple-RowSubqueries • Return more than one row of results • Require use of IN, ANY, ALL, or EXISTS operators Oracle9i: SQL

  12. ANY and ALL Operators Combine with arithmetic operators Oracle9i: SQL

  13. EXISTS Operator Determines whether condition exists in subquery Oracle9i: SQL

  14. Multiple-Row Subquery – In WHERE Clause Oracle9i: SQL

  15. Multiple-Row Subquery – In HAVING Clause Oracle9i: SQL

  16. 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 Oracle9i: SQL

  17. Multiple-Column Subquery – In FROM Clause Creates temporary table Oracle9i: SQL

  18. Multiple-Column Subquery –In WHERE Clause Returns multiple columns for evaluation Oracle9i: SQL

  19. NULL Values When subquery might return NULL values, use NVL function Oracle9i: SQL

  20. Uncorrelated Subqueries • Processing sequence: • Inner query executed first • Result passed to outer query • Outer query executed Oracle9i: SQL

  21. Correlated Subqueries • Inner query executed once for each row processed by outer query • Inner query references row contained in outer query Oracle9i: SQL

  22. 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. Oracle9i: SQL

  23. Nested Subquery Example Innermost resolved first (3), then second level (2), then outer query (1) Oracle9i: SQL

More Related