Define Subqueries

Define Subqueries.

A subquery is a query within a query. These sub queries are created with SQL statements. These subqueries are embedded within SELECT, FROM or the WHERE clause.

What is sub-query? Explain properties of sub-query.

A sub-query is a query embedded in another query. The sub query can be embedded in another SELECT, INSERT, UPDATE, or DELETE statement, or inside another sub query.

Properties:-
- The SELECT query of a subquery is always enclosed in parentheses
- View created by using a subquery cannot be updated.
- The ntext, text, and image data types cannot be used in the select list of sub queries
- If a table appears only in a subquery and not in the outer query, then columns from that table cannot be included in the output
Subqueries with IN and NOT IN
Sub Query Example with IN: Displays employees from employee table with bonus > 1000. Using IN first all employees are selected and compared to each row of the subquery.........
Subqueries with comparison operators
Comparison operators can be used (like <, >, =, !> etc). Sub queries used with comparison........
Subqueries with Exists and NOT Exists
A subquery with Exist does not really return any data; it returns TRUE or FALSE........
Post your comment