Thursday, February 21, 2013

SQL Subqueries

Print Friendly and PDF

Tremblant, Quebec
It is possible for SQL queries to contain other queries, called subqueries. The values of one query are passed to another query.

Subqueries can be utilized in SELECT statements, as well as the INSERT, UPDATE, and DELETE statements.

Subqueries allow you to connect queries together, so that you can query more than one table at a time.
Subqueries can either be nested within another query or it can be connected to another query using a keyword. When the subquery is nested in a SELECT statement, the innermost query is processed first. When a subquery is connected to another query using a keyword, the last subquery is processed first.

note: MySQL versions that are prior to version 4.1 do not support subqueries. MySQL uses JOINS to accomplish the same thing as subqueries.