Subqueries in SQL Server – SQL Server Tutorial

SUB QUERIES   :–

  • A query embeded in another query is called “sub querry”.
  • In this ,there will be two queries,one queries called inner-query and another query is called outer query.
  • When it is executed,first inner query is executed then outer query
  • The result of inner query act as input to outer query.

Types of sub queries  :-

  1. standard sub queries [follows where clause]
  2. derived tables [follows from clause]
  3. scalar subqueries [follows select clause]

 Standard sub queries  :–

  • Subqueries follows where clause (or) standard subquries.
  • Outer query can be  insert, Update, Delete, Select
  • Inner query must be always select.

Syntax :–   Select   <collist> from <tabname> where colname operation[select statement]

  • Use subqueries when where clause is based on unknown condition.

Types  of standard subqueries  :-

  1. Single row subquery
  2. multi row subquery
  3. nested queries
  4. co-related subqueries

Leave a Reply

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