Wednesday 19 June 2013

Leaaion 46 : Subquery




Subquery 

Subquery  is a query whithin  in a query. It is also called as Inner query or Nested query. A subquery is usually added in the WHERE clause of the sql statement.  Usually, a subquery is used when we know how to search for a value using a SELECT statement, but do not know the exact value.


Rules for Subqueries


· Must be enclosed in parentheses


· Can be the object of an IN or NOT IN clause

· Can be the object of EXISTS or NOT EXISTS clause

· Support quantifiers ALL, ANY, SOME

· Support LIKE or NOT LIKE used with a quantifier

· Can specify more than one column to match

· Generate a DISTINCT list of values


· Cannot use ORDER BY (within the subquery
statement).

·
Keep in mind that a maximum of 64
tables/views can be specified in an SQL
statement.