w3resource logo


gallery w3resource

SQL Subquery

Secondary Nav

Transcript

SQL Subquery

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

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.



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables