SQL joins are used to combine rows from two or more tables.
An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them.
The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER JOIN return all rows from multiple tables where the join condition is met.
Let's look at a selection from the "Orders" table:
Then, have a look at a selection from the "Customers" table:
|1||Alfreds Futterkiste||Maria Anders||Germany|
|2||Ana Trujillo Emparedados y helados||Ana Trujillo||Mexico|
|3||Antonio Moreno Taquería||Antonio Moreno||Mexico|
Notice that the "CustomerID" column in the "Orders" table refers to the customer in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.
Then, if we run the following SQL statement (that contains an INNER JOIN):
it will produce something like this:
|10308||Ana Trujillo Emparedados y helados||9/18/1996|
|10365||Antonio Moreno Taquería||11/27/1996|
|10383||Around the Horn||12/16/1996|
|10355||Around the Horn||11/15/1996|
Before we continue with examples, we will list the types the different SQL JOINs you can use:
Your message has been sent to W3Schools.