A subquery is often used inside a main query like Select, Update, Insert or Delete statements. A subquery can be used when expression is allowed. A subquery is also used to create a temporary table on which the main query is executed. Properties of sub query can be defined as follow
• Order By clause is not used with Subquery in SQL
• A sub query should be written in the right side of the comparison operator of the main query.
• A subquery is enclosed within the parenthesis because it is execute first before the main query.
• More than one sub query can be included in a main query.
Types of Subquery
There are generally three types of sub query –
• Single row sub query. It is returns only one row
• Multiple row sub query. It returns multiple rows
• Multiple column sub query. It returns multiple columns to the main query. Main query is executed according the sub query result.
Example-
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
SQL subquery and its property:
A subquery is often used inside a main query like Select, Update, Insert or Delete statements. A subquery can be used when expression is allowed. A subquery is also used to create a temporary table on which the main query is executed. Properties of sub query can be defined as follow
• Order By clause is not used with Subquery in SQL
• A sub query should be written in the right side of the comparison operator of the main query.
• A subquery is enclosed within the parenthesis because it is execute first before the main query.
• More than one sub query can be included in a main query.
Types of Subquery
There are generally three types of sub query –
• Single row sub query. It is returns only one row
• Multiple row sub query. It returns multiple rows
• Multiple column sub query. It returns multiple columns to the main query. Main query is executed according the sub query result.
Example-