0% found this document useful (0 votes)
49 views

Sub Queries: Author: JP: 1.0

There are three types of subqueries: single row, multiple row, and correlated. Subqueries allow queries to select data rows based on criteria determined during query execution. They can be used in the WHERE, FROM, and SELECT clauses. General rules are that a subquery SELECT statement is similar to a regular query SELECT, but can only return one expression, aggregate, or column. The values returned must be compatible with the outer query WHERE clause.

Uploaded by

redro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Sub Queries: Author: JP: 1.0

There are three types of subqueries: single row, multiple row, and correlated. Subqueries allow queries to select data rows based on criteria determined during query execution. They can be used in the WHERE, FROM, and SELECT clauses. General rules are that a subquery SELECT statement is similar to a regular query SELECT, but can only return one expression, aggregate, or column. The values returned must be compatible with the outer query WHERE clause.

Uploaded by

redro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Sub Queries

Author
Version

: JP
: 1.0

Define Sub Query


In Oracle, a sub-query is a query within a query.
You can create sub-queries within your SQL
statements. These sub-queries can reside in the
WHERE clause, the FROM clause, or the SELECT
clause.
Sub-queries enable you to write queries that select
data rows for criteria that are actually developed
while the query is executing at run time.

Sub Query Types

There are three basic types of subqueries


Single Row Sub Query: Sub query which returns single row output. They mark the
usage of single row comparison operators, when used in WHERE conditions.
Multiple row sub query: Sub query returning multiple row output. They make use
of multiple row comparison operators like IN, ANY, ALL. There can be sub queries
returning multiple columns also.
Correlated Sub Query: Correlated subqueries depend on data provided by the
outer query.This type of subquery also includes subqueries that use the EXISTS
operator to test the existence of data rows satisfying specified criteria.
Subqueries that operate on lists by use of the IN operator or with a comparison
operator modified by the ANY or ALL optional keywords. These subqueries can
return a group of values, but the values must be from a single column of a table.
Subqueries that use an unmodified comparison operator (=, <, >, <>) these
subqueries must return only a single, scalar value.
Subqueries that use the EXISTS operator to test the existence of data rows
satisfying specified criteria.

General Rules

A subquery SELECT statement is very similar to the SELECT


statement used to begin a regular or outer query. The complete
syntax of a subquery is shown below.
( SELECT [DISTINCT] subquery_select_argument
FROM {table_name | view_name}
{table_name | view_name} ...
[WHERE search_conditions]
[GROUP BY aggregate_expression [, aggregate_expression] ...]
[HAVING search_conditions] )

The SELECT clause of a subquery must contain only one expression,


only one aggregate function, or only one column name.
The value(s) returned by a subquery must be join-compatible with the
WHERE clause of the outer query

You might also like