Week-8 Class Exercise Ques
Week-8 Class Exercise Ques
Exercise
1. Write a SELECT statement that joins the Courses table to the Departments table and returns these
columns: CourseNumber, CourseDescription, DepartmentName.
Sort the result set by DepartmentName and then by CourseNumber in ascending order.
2. Write a SELECT statement that joins the Instructors table to the Courses table and returns these
columns: LastName, FirstName, CourseNumber, CourseDescription.
Return all courses for each instructor with a status of “P” (part time).
Sort the result set by LastName and then by FirstName in ascending order.
3. Write a SELECT statement that joins the Departments, Courses, and Instructors tables. This statement
should return these columns: DepartmentName, CourseDescription, FirstName, and LastName.
Use aliases for the tables, and return only those courses with three units.
Sort the result set by DepartmentName and then by CourseDescription in ascending sequence.
4. Write a SELECT statement that joins the Departments, Courses, StudentCourses, and Students tables.
This statement should return these columns: DepartmentName, CourseDescription, LastName, and
FirstName.
Return all courses in the English department.
Sort the result set by DepartmentName and then by CourseDescription in ascending sequence.
5. Write a SELECT statement that joins the Instructors and Courses tables and returns these columns:
LastName, FirstName, and CourseDescription.
Return at least one row for each instructor, even if that instructor isn’t teaching any courses.
Sort the result set by LastName and then by FirstName.
6. Use the UNION operator to generate a result set consisting of five columns from the
Students table:
Status A calculated column that contains a value of UNDERGRAD or
GRADUATED
FirstName The FirstName column
LastName The LastName column
EnrollmentDate The EnrollmentDate column
GraduationDate The GraduationDate column
If the student doesn’t have a value in the GraduationDate column, the Status column should contain a
value of UNDERGRAD. Otherwise, it should contain a value of GRADUATED.
Sort the final result set by EnrollmentDate.
7. Write a SELECT statement that returns these two columns:
DepartmentName The DepartmentName column from the Departments table
CourseID The CourseID column from the Courses table
Return one row for each Department with no courses. (Hint: Use an outer join and only return rows
where the CourseID column contains a null value.)
8. Write a SELECT statement that returns these columns:
InstructorDept The DepartmentName column from the Departments table for a
related instructor
LastName The LastName column from the Instructors table
FirstName The FirstName column from the Instructors table
CourseDescription The CourseDescription column from the Courses table
CourseDept The DepartmentName column from the Departments table for a
related instructor
Return one row for each course that’s in a different department than the department of the instructor
assigned to teach that course. (Hint: You will need to join the Departments table to both the
Instructors table and the Courses table, which will require you to use table aliases to distinguish the
two tables.)