Sub -Query
Subquery is query within a query.
A SELECT statement can be nested inside another query
to form a subquery.
The query which contains the subquery is called outer
query.
Scalar Sub-query
A scalar subquery returns single row, single column result.
Q)Find the name of the student who has opted for the course RDBMS
Sol: select sname from student where sid=(select sid from
course where cname=‘RDBMS’);
Correlated subquery
the processing of subquery requires data from the outer query
Sub-query always depends on the results of outer sub-query.
Exists operator is used to find out subquery contains values
returned by outer query.
Not exists operator is used to find out subquery must not
contains values returned by outer query
ex
Select orderid from orders where
Exists(
select * from product
where orders.productid = product.productid
and product.productname=‘Mobile’);

Sub -Query in Database management system.pptx

  • 1.
  • 2.
    Subquery is querywithin a query. A SELECT statement can be nested inside another query to form a subquery. The query which contains the subquery is called outer query.
  • 3.
    Scalar Sub-query A scalarsubquery returns single row, single column result. Q)Find the name of the student who has opted for the course RDBMS Sol: select sname from student where sid=(select sid from course where cname=‘RDBMS’);
  • 4.
    Correlated subquery the processingof subquery requires data from the outer query Sub-query always depends on the results of outer sub-query. Exists operator is used to find out subquery contains values returned by outer query. Not exists operator is used to find out subquery must not contains values returned by outer query
  • 5.
    ex Select orderid fromorders where Exists( select * from product where orders.productid = product.productid and product.productname=‘Mobile’);