Define sub-query.
- Sub-query is a query within a query.
- It is used to return data that will be used in the main query as a condition.
- These subqueries can be used with the SELECT, INSERT, UPDATE and DELETE statements.
- While writing the subquery it must be enclosed within the parentheses.
- Subquery is usually added in the 'WHERE' clause.
Syntax:SELECT column_name1, column_name2, ā¦
FROM table1, table2
WHERE column_name OPERATOR
(SELECT column_name1 FROM table1);
Example:SELECT eId, ename
FROM employee
WHERE e_Id IN
(SELECT dept_Id FROM department);