Database - SUB QUERY


  A query inside another query is known as subquery.
A subquery is also called an inner query or inner select,
while the statement containing a subquery is also called an outer query or outer select.
Types of subquery
1.independent subquery
2.correlated subquery



INDEPENDENT SUBQUERY

    The inner query and the outer query can be executed independently.
They independent to each other.

select * from stud where courseid =(select courseid from course where duration = 2)



CORRELATED SUBQUERY

   The inner query and the outer query are dependent on each other.
The cannot be executed seperately.

select sid,sname from stud s1 where s1.courseid =
 ( select avg(courseid) from stud s2 where s1.sid = s2.sid )

Comments

Popular posts from this blog

How to set Java Object into JaxBElement ?

GitLab