A SubQuery is a query within another query. The outer query is called as main query and inner query is called as SubQuery.
The SubQuery generally executes first, and its output is used to complete the query condition for the main or outer query. Subquery must be enclosed in parentheses.
Subqueries are on the right side of the comparison operator. You can place the Subquery in a number of SQL clauses: WHERE clause, HAVING clause, FROM clause.
Subqueries can be used with SELECT, UPDATE, INSERT, DELETE statements along with expression operator. It could be equality operator or comparison operator such as =, >, =, <= and Like operator.
ORDER BY command cannot be used in a SubQuery. GROUPBY command can be used to perform same function as ORDER BY command.
A Sample Syntax Example for SubQuery:
WHERE column_name expression operator
( SELECT COLUMN_NAME from TABLE_NAME WHERE … );