SQL joins are used to query data from two or more tables, based on a relationship between certain columns in these tables.
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.
Look at the selection from the "Customers" table:
||Alfreds Futterkiste||Maria Anders||Obere Str. 57||Berlin||12209||Germany|
|2||Ana Trujillo Emparedados y helados||Ana Trujillo||Avda. de la Constitución 2222||México D.F.||05021||Mexico|
|3||Antonio Moreno Taquería||Antonio Moreno||Mataderos 2312||México D.F.||05023||Mexico|
Note that the "CustomerID" column is the primary key in the "Customers" table. This means that no two rows can have the same "CustomerID". The "CustomerID" distinguishes two companies even if they have the same name.
Next, we have the selection from the "Orders" table:
Note that the "OrderID" column is the primary key in the "Orders" table and that the "CustomerID" column refers to the company in the "Customers" table without using their name.
Notice that the relationship between the two tables above is the "CustomerID" column.
Before we continue with examples, we will list the types of JOIN you can use, and the differences between them.
Your message has been sent to W3Schools.