You are on page 1of 11

EXERCISE 5: SQL subqueries & set theoretic functions

Faculty Name: Dr. Abishi Chowdhury


Lab Slot: L15+L16
Class Number: CH2022235002536
SHRESTHA SINGH
21BRS1686
1. Create the following relations:

Student_shrestha86 (sID: int, sName: varchar2(10), CGPA: int, city: varchar2(15), phone_number: int)

Apply_shrestha86 (sID: int, cName: varchar2(20), stream: varchar2(10))

College_shrestha86 (cName: varchar2(20), state: varchar2(15))


Write SQL queries for the following:

2. Insert 10 tuples in each relation.

insert into student_shrestha86 values(01,'Sid',8,'Pune',9604801210);

insert into student_shrestha86 values(02,'Jhon',9,'Mumbai',8104768951);

insert into student_shrestha86 values(03,'Amy',7,'Delhi',7428223755);

insert into student_shrestha86 values(04,'Jay',8,'Bangalore',9035790945);

insert into student_shrestha86 values(05,'Nikhil',7,'Noida',1111111111);

insert into student_shrestha86 values(06,'Aarnav',6,'Delhi',2222222222);

insert into student_shrestha86 values(07,'Tanishq',8,'Bhubaneshwar',3333333333);

insert into student_shrestha86 values(08,'Dweep',7,'Goa',4444444444);

insert into student_shrestha86 values(09,'Zain',9,'Pune',5555555555);

insert into student_shrestha86 values(10,'Faizal',5,'Delhi',6666666666);


insert into apply_shrestha86 values(01,'Sid','CSE');

insert into apply_shrestha86 values(02,'Jhon','Law');

insert into apply_shrestha86 values(03,'Amy','Civil');

insert into apply_shrestha86 values(04,'Jay','CSE');

insert into apply_shrestha86 values(05,'Nikhil','Law');

insert into apply_shrestha86 values(06,'Aarnav','CSE');

insert into apply_shrestha86 values(07,'Tanishq','Maths');

insert into apply_shrestha86 values(08,'Dweep','Biotech');

insert into apply_shrestha86 values(09,'Zain','CSE');

insert into apply_shrestha86 values(10,'Faizal','Civil’);

insert into college_shrestha86 values('MIT','Boston');

insert into college_shrestha86 values('VIT','Chennai');

insert into college_shrestha86 values('MIT','Boston');

insert into college_shrestha86 values('DAV','Delhi');

insert into college_shrestha86 values('DAV','Delhi');


insert into college_shrestha86 values('MIT','Boston');

insert into college_shrestha86 values('DAV','Delhi');

insert into college_shrestha86 values('VIT','Chennai');

insert into college_shrestha86 values('VIT','Chennai');

insert into college_shrestha86 values('DAV','Delhi');

3. Find IDs and names of students who have applied in CSE stream at some college.
4. Find the name of student with their CGPA and Sid whose CGPA not equal to CGPA of Jhon.

5. Find college where students having their names started with S have applied.
6. Find IDs of student and major who applied in any of major Amy had applied to. But exclude Amy sID
from the list.

SELECT a.sID, a.stream

FROM Apply_shrestha86 a

JOIN (SELECT cName FROM Apply_shrestha86 WHERE sID = (SELECT sID FROM Student_shrestha86 WHERE sName= 'Amy'))
Amycolleges ON a.cName = Amycolleges.cName

WHERE a.sID != (SELECT sID FROM Student_shrestha86 WHERE sName='Amy');

7. Find sID of student who applied to more or same number of college where Jay has applied.
8. Find details of Students who applied to stream CSE but not applied to stream ECE.
9. Find all the colleges such that some other colleges are in the same state.

no data found

10. Find name of student having lowest CGPA.


11. Find sID, sName, city of all students NOT from lowest CGPA.
12. Find sID of students who have not applied to DAV college.

13. Find the names of students who applied to all the colleges where sID 12 has applied.
14. Delete applications that are filed to state ‘Boston’.

You might also like