In addition, a correlated subquery may be evaluated once for each row selected by the outer query. Because of this, a query that uses a correlated subquery could be slow. A correlated subquery is also known as a repeating subquery or a synchronized subquery. The following query finds all products whose list price is above average for their category. What Is an Equijoin?
If you can't read please download the document. Post on May Category: Technology download. Tags: character functions types of sql functions oracle9i database writing sql statements oracle products capabilities of sql writing basic sql case manipulation functions.
Introduction to oracle 9i sql chapters 1 Oracle 9i upgrade exam This can help if you want to use this subquery many times. For example if you want to find:. You need to group the bricks by colour. And compute the mean of the counts. You can do the filtering with a nested subquery. And show the average in a scalar subquery. This looks like:. Note that "group by colour" appears twice in the statement. This creates maintenance problems. If you need to change this, say to join bricks to another table, you have to do this in two places.
Oracle Database can also optimize queries that access the same CTE many times. This can make it more efficient than regular subqueries. Literate programming is a concept introduced by Donald Knuth.
The idea is to write code that makes sense if you read it like a book: from start to finish. Simple SQL queries follow this principle.
But subqueries usually break this human readable flow. For example, if you want to find which bricks you have less of than the average number of each colour, you need to:. Step one is at the bottom of the query! Using CTEs, you can order the subqueries to match the logic above:. If you want to check that the brick counts from the previous query are correct, update the final from clause:.
Live SQL. Module 1. You do this by placing the subquery in the FROM clause of the containing query as you would a table name.
Subqueries so used can employ correlation variables, but only those defined within the subquery itself, not outer references. Scalar subqueries, which return a single column value from a single row, are a valid form of expression. You can use scalar subquery expressions in most of the places where expr is called for in syntax.
0コメント