What is Nested Queries explain in details?
Nested Queries - A SELECT query could have subquery(s) in it. While a SELECT query having another SELECT query in it, is known as nested query. A few operations cannot be performed along with single SELECT command or along with join operation. There are some operations that can be performed along with the help of nested queries (also referred to as subqueries). For instance, we want to calculate the second highest salary:
SELECT MAX(SAL) FROM EMP WHERE SAL < (SELECT MAX(SAL) FROM EMP)
Some operations can be performed both through Join and subqueries. The Join operation is costlier in terms of space and time. Thus, the solution based on subqueries is preferred.