Sunteți pe pagina 1din 6

REGISTRATION NUMBER : 19MCA1116

NAME : Hari Shankar


Ex No : 5
Date : 31-AUG-2019
Title : JOINS

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------------------------

Create the following schema:

a. student(regno, sname, cgpa) :

SQL> create table student(regno varchar(10),sname varchar(20),cgpa


number(4,1),constraint pk primary key(regno));

Table created.

b. course(ccode, cname, credits) :

create table course(ccode varchar(10),cname varchar(20),credits


number(5),constraint pk1 primary key(ccode));

Table created.

c. faculty(fid, fname, designation) :

SQL> create table faculty(fid varchar(10),fname varchar(20),designation


varchar(20),constraint pk2 primary key(fid));

Table created.

d. course_student(regno, ccode):

SQL> create table course_student(regno varchar(10),ccode


varchar(20),constraint fk1 foreign key(regno) references student,constraint fk2
foreign key(ccode) references course);

Table created.

e. course_faculty(fid, ccode):

SQL> create table course_faculty(fid varchar(10),ccode


varchar(20),constraint fk3 foreign key(fid) references faculty,constraint fk4
foreign key(ccode) references course);

Table created.

Inser the values in all table:

a. Values in student table:

SQL> insert into student values('19MCA1001','Shivam',8.5);

1 row created.
SQL> insert into student values('19MCA1002','Raga',9.0);

1 row created.

SQL> insert into student values('19MCA1003','Natthu',8.7);

1 row created.

SQL> insert into student values('19MCA1004','Krish',9.3);

1 row created.

SQL> insert into student values('19MCA1005','Alumal',9.1);

1 row created.

b. Values in course table:

SQL> insert into course values('CSE1001','statistics',3);

1 row created.

SQL> insert into course values('CSE2002 ','data structure',4);

1 row created.

SQL> insert into course values('CSE2004','networking',2);

1 row created.

SQL> insert into course values('CSE3002','database',4);

1 row created.

SQL> insert into course values('CSE3001','python',5);

1 row created.

c. Values in faculty table:

SQL> insert into faculty values('FID1001','Anand','professor');

1 row created.

SQL> insert into faculty values('FID1002','sai','professor');

1 row created.

SQL> insert into faculty


values('FID1003','premalatha','asst_professor');

1 row created.

SQL> insert into faculty values('FID1004','rekha','program_chair');

1 row created.

SQL> insert into faculty values('FID1005','jaya','professor');


1 row created.

d. values in student_course:

SQL> insert into course_student values('19MCA1001','CSE2004');

1 row created.

SQL> insert into course_student values('19MCA1002','CSE3002');

1 row created.

SQL> insert into course_student values('19MCA1003','CSE3002');

1 row created.

SQL> insert into course_student values('19MCA1004','CSE2004');

1 row created.

SQL> insert into course_student values('19MCA1005','CSE1001');

1 row created.

e. values in course_faculty:

SQL> insert into course_faculty values('FID1001','CSE2004');

1 row created.

SQL> insert into course_faculty values('FID1002','CSE2004');

1 row created.

SQL> insert into course_faculty values('FID1003','CSE3002');

1 row created.

SQL> insert into course_faculty values('FID1004','CSE1001');

1 row created.

SQL> insert into course_faculty values('FID1005','CSE2002');

1 row created.
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

All Schemas Of Tables:-

a.) Student table:

REGNO SNAME CGPA


----------------- ---------------- ------------
19MCA1001 Shuvam 8.5
19MCA1002 Raga 9.1
19MCA1003 Natthu 9.5
19MCA1004 Krish 9.3
19MCA1005 Aalumal 9.1

b.) Course table:

CCODE CNAME CREDITS


-------------- ------------------------- ----------
CSE1001 statistics 3
CSE2002 data structure 4
CSE2004 networking 2
CSE3002 database 4
CSE3001 python 5

c.) Faculty table:

FID FNAME DESIGNATION


------------- -------------------- --------------------
FID1001 Anand professor
FID1002 sai professor
FID1003 premalatha asst_professor
FID1004 rekha program_chair
FID1005 jaya professor

d.) Course_student table:

REGNO CCODE
------------------ --------------------
19MCA1001 CSE2004
19MCA1002 CSE3002
19MCA1003 CSE3002
19MCA1004 CSE2004
19MCA1005 CSE1001

e.) Course_faculty table:

FID CCODE
------------- --------------------
FID1001 CSE2004
FID1002 CSE2004
FID1003 CSE3002
FID1004 CSE1001
FID1005 CSE2002

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Q1.) List the students details who have taken CSE2004.

SQL> select * from student natural join course_student where ccode='CSE2004';

REGNO SNAME CGPA CCODE


----------------- -------------------- ---------- --------------------
19MCA1001 Shivam 8.5 CSE2004
19MCA1004 Krish 9.3 CSE2004

Q2.) List the faculty names with designation �Professor� who teaches CSE2004
[Natural Join and Explicit Inner Join]
USING NATURAL JOIN:-

SQL> select fname from faculty natural join course_faculty where


designation='professor' and ccode='CSE2004';

FNAME
--------------------
Anand
sai

USING INNER JOIN:-

SQL> select faculty.fname from faculty inner join course_faculty on faculty.fid =


course_faculty.fid where designation ='professor' and ccode='CSE2004';

FNAME
--------------------
Anand
sai

Q3.) List the courses with more than 2 credits which was taught by the faculty
�Anand�

SQL> select cname,fname from course inner join course_faculty on


course.ccode=course_faculty.ccode inner join faculty on
faculty.fid=course_faculty.fid where course.credits>2 and faculty.fname='Anand';

CNAME FNAME
-------------------- --------------------
networking Anand
database Anand

Q4.) List the students with >9 CGPA and has taken CSE3002 course taught by �Prof.
Sai�

SQL> select distinct(regno),sname,cgpa from student natural join course_student


natural join course_faculty natural join faculty where ccode='CSE3002' and
fname='sai' and cgpa>9;

REGNO SNAME CGPA


----------------- -------------------- ----------
19MCA1003 Natthu 9.5
19MCA1002 Raga 9.1

Q5.) List the register number, name, course code, course name and faculty empid,
name involved in the course CSE1001

SQL> select regno,sname,ccode,cname,fid,fname from student natural join course


natural join faculty natural join course_student natural join course_faculty where
ccode='CSE1001';

REGNO SNAME CCODE CNAME FID FNAME


----------------- ---------------- -------------------- ------------------
------------- --------------
19MCA1005 Alumal CSE1001 statistics FID1004 rekha

Q6.) List the students who have not registered any courses

SQL> select sname from student natural join course where cname='NULL';
no rows selected

Q7.) List the faculty who teaches more than 1 course

SQL> select fname,count(ccode)from course_faculty natural join faculty group by


fname having count(ccode)>1;

FNAME COUNT(CCODE)
-------------------- --------------------------
Anand 2
sai 2

Q8.) List the name of the faculty along with the name of the course he/she handles

select fname,cname from faculty natural join course_faculty natural join course;

FNAME CNAME
-------------------- --------------------
Raman software engineering
Anand software engineering
Anand applied statistics
Vijay big data
Chandan neural networks
Sai machine learning
Sai neural networks

Q9.) Count the number of courses handled by each faculty

SQL> select fname,count(ccode)from course_faculty natural join faculty group by


fname;

FNAME COUNT(CCODE)
-------------------- ------------
Anand 2
sai 2
rekha 1

Q10.) List the number of students who have registered for more than 10 credits

select count(regno),sum(credits) from course_student natural join course group by


regno having sum(credits)>10;

no rows selected

S-ar putea să vă placă și