Skip to main content

Extending Links

Let us extend the above selection to include the name of the department in which the student is enrolled. The department name can be found in the department table. We will also include the course number and department number in the columns to be displayed.

The join statement linking two tables

SELECT student_number, title, forename, surname, student.course_number, course_name, department.dept_number, dept_name

FROM student, course, department

WHERE student.course_number = course.course_number

AND student.dept_number = department.dept_number;

As you can see, the course_number in the list of columns to be displayed is prefixed with the table name 'student'. It could also have been prefixed with the table name 'course'. It does not matter which one is chosen. However, if you forget the table name prefix you will get an error message. It is the same for the dept_number.

Now it is your turn to have a go at selecting data from multiple tables. All of the following queries are performed using the student database.

Next: Activity 2.5