gallery w3resource

SQL Subquery


SQL Subquery

<!doctype html>
<html lang="en">
<title>SQL Subquery </title>

What is SQL Sqbquery?

A subquery is a SQL query nested inside a larger query.

Where Subquery Occurs?

A subquery may occur in -

  • A SELECT clause
  • A FROM clause
  • A WHERE clause
  • The subquery can be nested inside a SELECT,INSERT,UPDATE,or DELETE statement or inside another subquery.
  • A subquery is usually added within the WHERE Clause of another SQL SELECT statement.
  • You can use the comparison operators, such as >, <, or =.

Subquery Syntax

  • The subquery (inner query) executes before the main query (outer query).
  • The result of the subquery is used by the main query.

Type of Subqueries

  • Single row subquery : Returns zero or one row.
  • Multiple row subquery : Returns one or more rows.
  • Multiple column subquery : Returns one or more columns.
  • Correlated subqueries : Reference one or more columns in the outer SQL statement.
  • Nested subqueries : Subqueries are placed within another subqueries.

Follow us on Facebook and Twitter for latest update.