The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.
Tables in a database are often related to each other with keys.
A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.
Table Name ” emp”
Note that the “S.no” column is the primary key in the “emp” table. This means that no two rows can have the same S.no. The S.no distinguishes two persons even if they have the same name.
Next, we have the “job” table:
Table Name “job”
Note that the “J.Id” column is the primary key in the “job” table and that the “S.no” column refers to the persons in the “emp” table without using their names.
Notice that the relationship between the two tables above is the “S.no” column.
Different SQL JOINs
we will list the types of JOIN you can use, and the differences between them.
JOIN: Return rows when there is at least one match in both tables LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table FULL JOIN: Return rows when there is a match in one of the tables