Assignment 2
Assignment 2
Topics covered: Creating Tables, Inserting Multiple Rows,Equi Join, Non Equi Join, Outer Join
a. Write below Teachers Table Query [with all Primary Key and Foreign Key constraints if needed]
CREATE TABLE teachers
Designation varchar(30),
Dept_id number(10),
Salary number(20)
);
b.Write below Courses Table Query[with all Primary Key and Foreign Key constraints if needed]
CREATE TABLE courses
Course_name varchar(30),
Credit_hours number(10)
);
c. Write below Dept Table Query[with all Primary Key and Foreign Key constraints if needed]
CREATE TABLE depttable
Dept_name varchar(30),
Phone number(20),
Location varchar(30)
);
d. Write below Assigned_Courses Table Query[with all Primary Key and Foreign Key
constraints if needed]
values('1','3','102','10:10am','class 03');
values('2','3','109','11:10am','class 04');
values('3','1','104','12:10pm','class 01');
values('4','1','103','01:00pm','class 02');
values('5','4','101','09:00am','class 08');
values('6','4','106','11:00am','class 08');
values('7','7','108','02:00pm','class 09');
values('8','5','106','01:00pm','class 01');
values('9','','105','02:00pm','class 02');
e.Write below Job_grades Table Query[with all Primary Key and Foreign Key constraints if
needed]
Q2. Write query on above given tables (teachers, courses, assigned_courses) to show following output
[Hint: Use 2 Equi Joins or Inner Joins][Teachers and Courses with Assigned_Courses table]
select a.ac_id,t.teacher_name,c.course_name
from assignedcourses a,teachers t,courses c
where a.teacher_id=t.teacher_id and a.course_id=c.course_id order
by(ac_id);
Q3. Write query on above given tables (teacher and dept) to show following ouput.
SELECT teacher_id,teacher_name,designation,dept_name
FROM teachers
LEFT JOIN depttable
ON teachers.teacher_id = depttable.dept_id;
Q4. Write query on above given tables (teachers, dept) to show following output
SELECT t.teacher_id,t.teacher_name,t.designation,t.salary,j.grade_name
SELECT t.teacher_id,t.teacher_name,t.designation,t.salary,j.grade_name
from teachers t,job_grades j
where t.salary between j.lowest_salary and j.highest_salary
and
j.grade_name='E'
------------------------------------------------------------------------------------------------------------------------------------------