I have a the following tables
- students(sid, sname, age)
- course(cid, cname, duration)
- enroll(sid, cid, date)
To find all sid’s who had taken the courses which sid = 1 has taken.
select sid from enroll where cid in (select cid from enroll where sid=1)
group by sid having count(*)=(select count(*) from enroll where sid=1)
minus (select sid from student where sid=1);
- What does the first count(*) refers to?
- Is there a simpler version of the query?
The first
COUNT(*)refers to the count of the rows belonging to a particularsid.Reformatted:
You can certainly avoid the MINUS by using: