SQL Joins

SQL JOIN 

A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

Orders table:

OrderID

CustomerID

OrderDate

10308

2

1996-09-18

10309

37

1996-09-19

10310

77

1996-09-20


 Customers table:

CustomerID

CustomerName

ContactName

Country

1

om

8877665544

India

2

ved

9900776655

Germany

3

Kushbu

9966092089

Mexico


Customers table:

Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.

Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records that have matching values in both tables:

Example : 

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate

FROM Orders

INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

The OUTPUT for the above query:

OrderID

CustomerName

OrderDate

10308

om

9/18/1996

10365

anu

11/27/1996

10383

sneha

12/16/1996

10355
ashok11/15/1996
10278
mony
8/12/1996