Let’s say we want to display the name of each student who is enrolled in a course and the names of the courses they are enrolled in.

Since the name of the student, and the name of the course exist in two different tables (students and courses respectively), we need to use JOIN to combine the two tables.

The query will look like this

Observe closely, and you can figure out the basic syntax of a JOIN query

  1. the SELECT part: specify the list of columns you need, just like list of columns you mention in normal SELECT queries, but this time, specifying the table from which each column is picked before it, with a dot (.) operator. Eg.,

  2. the FROM part: list of tables the columns are being picked from, separated by the word JOIN. Eg. students JOIN courses

  3. the ON part: This is key part of a JOIN query. It is used to express the columns from each table which should be matched together to connect the data amongst them. In this case, the column courseId in students stores the reference to the courses students are enrolled in, in the form of id from the actual id column from the courses table. Hence, the clause, ON students.courseId =