2. WHAT IS A SUBQUERY?
A subquery is a SELECT statement embedded in a clause of another SQL statement (SELECT, INSERT,
UPDATE, DELETE).
SQL subquery is usually added in the WHERE Clause of the SQL statement.
SELECT . . .
FROM . . .
WHERE . . .
(SELECT . . .
FROM . . .
WHERE . . .)
Main
Query
Subquery
3. SUBQUERY
Subquery or Inner query or Nested query.
An alternate way of returning data from multiple tables.
Subqueries can be used with the following SQL statements along with the comparison operators like =,
<, >, >=, <= etc.
Subqueries can also be used inside the WHERE or HAVING clause.
SELECT select_list
From table
WHERE OOP operator SELECT select_list
From table
4. SUB-QUERY SYNTAX
The subquery (inner query) executes once
before the main query.
The result of the subquery is used by the
main query (outer query).