SQL Sub queries are the queries which are set inside another query. The set queries are called as INNER query & container query is called as OUTER query.

The subqueries are the queries which are executed inside of another query. The result SQL query is totally depends on the result of sub query. First the INNER query gets executed & the result of INNER query is passed as input to the outer query.

SQL Sub-Query Syntax:

Basic syntax of the SQL Sub query command:

SELECT * FROM TABLE1  WHERE COLUMN_NAME(S)=(SELECT COLUMN_NAME(S) FROM TABLE2)

Three types of sub queries SQL

  • The Scalar subquery result returns only a single row and single column.
  • The Row subquery result returns only a single row with single/multiple column(s).
  • The Table subquery result returns can be return single/multiple row(s) or column(s).

Leave a Reply

Your email address will not be published. Required fields are marked *