Nested select statement work procedure

by Joniur programmer   Last Updated October 19, 2019 12:06 PM

I was wondering how nested select statement works.

Let me be clear with an example(with an academic example). According to Database system concept of Silberschatz I am using an university database. And here is link to schema.

If I want to "Find the enrolment of each section that was offered in Fall 2017" one way to query database is :


select 
  course_id, 
  sec_id,
  (select 
       count(ID) 
   from 
       takes 
   where 
       takes.year = section.year and
       takes.semester = section.semester and 
       takes.course_id = section.course_id and 
       takes.sec_id = section.sec_id)
from 
    section 
where 
    semester = 'Fall' and year = 2017;

I want to know how inner select statement matches rows with course_id and sec_id.

Thanks



Related Questions


Updated June 21, 2019 11:06 AM

Updated May 17, 2015 21:02 PM

Updated January 03, 2018 01:06 AM

Updated October 09, 2018 00:06 AM

Updated July 22, 2018 09:06 AM