NESTED QUERIES DBMS
In Nested Queries, a query is written inside a query. The result of inner query is used in the execution of the outer query.
There are mainly two types of nested queries:
- Independent Nested Queries: In independent nested queries, query execution starts from inner query to outer query. The execution of inner query is independent of the outer query, but the result of inner query is used in the execution of the outer query. For Example: select S_NAME from STUDENT where S_ID IN (select S_ID from STUDENT_COURSE where C_ID IN (select C_ID from COURSE where C_NAME='DSA' or C_NAME='DBMS'));
- Co-Related Nested queries: In co-related nested query, the output of the inner query depends on the row which is being currently executed in outer query as: select S_NAME from STUDENT S where (select * from STUDENT_COURSE SC where S.S_ID = SC.S_ID and SC.C_ID = 'C1')
Source: GeeksForGeeks
Comments
Post a Comment