SQL Joins

SQL JOIN keyword is used to combines the rows from two or more tables, based on the common field between them.

Types of SQL JOIN Keyword

There are the following different types of JOIN available in SQL:

  • SQL INNER JOIN - The SQL INNER JOIN returns the rows only when there is a match found in both the tables
  • SQL RIGHT JOIN - The SQL RIGHT JOIN returns all the rows from the right table, even if there are no matches found in the left table
  • SQL FULL JOIN - The SQL FULL JOIN returns the rows only when there is a match found in one of the tables
  • SQL LEFT JOIN - The SQL LEFT JOIN returns all the rows from the left table, even if there are no matches found in the right table
  • SQL SELF JOIN - The SQL SELF JOIN is used to join a table to itself as if the table were two tables, temporarily renaming at least one table in the SQL statement
  • SQL CARTESIAN JOIN - The SQL CARTESIAN JOIN returns the Cartesian product of the sets of records from two or more joined tables

SQL JOIN Keyword Example

Here is an example of SQL JOIN Keyword. Let's look at the following table we have i.e., the "Admissions" table:

sql joins keyword

Let's look at the following one more table we have i.e., the "Students" table:

sql joins clause

Notice that the column "StudentID" in the table "Admissions" refers to the column "StudentID" in the table "Students".

Now we can perform the SQL JOIN operation to display the records of the two given table (above two table) here, having the common column StudentID.

For the SQL JOIN operation, both the tables must have at least one common column (here StudentID).

The relationship between the two tables shown above is the column "StudentID".

Then, if we run the following SQL statement (that contains an INNER JOIN):

SELECT Admissions.StudentID, Students.Name, Admissions.AdmissionYear
FROM Admissions
INNER JOIN Students
ON Admissions.StudentID=Students.StudentID;

After querying the above SQL statements, you will get the following output:

sql inner join

SQL Online Test


« Previous Tutorial Next Tutorial »

Like/Share Us on Facebook 😋