Subquery and Join Gim
Subquery and Join Gim
select regno,sname from student where dno= (select dno from department ); //error
select regno,sname from student where dno= (select dno from department where dname='IT' );
//Display the students who studies in the department same as that of faculty Harshitha
select * from student where dno = (select dno from faculty where faculty_name='Harshitha');
//List the details of the student under Faculty Mala and Balakumar
select * from student where dno = (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Balakumar'); //error
select * from student where dno in (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Balakumar');
select * from student where dno in (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Balakumar');
select * from student where dno =any (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Balakumar');
select * from student where dno >any (select dno from faculty where faculty_name = 'Mala');
select * from student where dno <any (select dno from faculty where faculty_name = 'Raja');
select * from student where dno =any (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Raja');
select * from student where dno > any (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Raja');
select * from student where dno < any (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Raja');
select * from student where dno < all (select dno from faculty where faculty_name='Raja' or
faculty_name='Balakumar');
select * from student where dno > all (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Raja');
select * from student where dno <any (select dno from faculty where faculty_name = 'Mala' or
faculty_name='Balakumar');
select * from student where dno =any (select dno from faculty where faculty_name = 'Mala') ;
select * from student where dno =all (select dno from faculty where faculty_name = 'Mala') ;
select * from student where dno >any (select dno from faculty where faculty_name = 'Mala') ;
select * from student where dno >all (select dno from faculty where faculty_name = 'Mala') ;
select * from student where dno > any (select dno from faculty where faculty_name='Raja' or
faculty_name='Mala');
select * from student where dno > all (select dno from faculty where faculty_name='Raja' or
faculty_name='Mala');
//self join display the details of the students who got same marks
SELECT A.sname AS student1, B.sname AS student2, A.marks FROM student A, student B wHERE
A.regno <> B.regno AND A.marks = B.marks;
select sname from student where marks= any(select marks from student group by marks having
count(*) >1);
Select s.sname ,s1.marks from student s, student s1 where s.marks = s1.marks and s.sname !=
s1.sname;