WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL INNER JOIN Keyword


SQL INNER JOIN Keyword

The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.

SQL INNER JOIN Syntax

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;

or:

SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name;

PS! INNER JOIN is the same as JOIN.

SQL INNER JOIN


Database

In this tutorial we will use the well-known database.

Below is a selection from the "Customers" table:

CustomerID PersonName Username password email
1

Emily L. Gamble Ankind Chum4Cu2ah EmilyLGamble@armyspy.com
2 Jeff L. Robinson Horks1963 boh6taBio JeffLRobinson@rhyta.com
3 Donna M. Montgomery Stareer oopei7hoSah DonnaMMontgomery@jourrapide.com

And a selection from the "Orders" table:

OrderID CustomerID EmployeeID OrderDate ShipperID
10308 2 7 2001-10-05 3
10309 37 3 1999-12-05 1
10310 77 8 1989-12-15 2

SQL INNER JOIN Example

The following SQL statement will return all customers with orders:

Example

SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
INNER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;

Note: The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns. If there are rows in the "Customers" table that do not have matches in "Orders", these customers will NOT be listed.