Learn SQL

Aliasing table names in JOIN

Let’s say the task is to display id and name of students who have are enrolled in a course that exists along with the id and name of the courses. The following query would work.

However, the repetition of the table names in SELECT list and ON clause can be reduced by aliasing the table names themselves, and then using the aliases to point out the columns themselves.

Observe that we have aliased the tables students and courses to s and c respectively in the JOIN list, and then we have used those aliases in SELECT and ON clauses.