Inner Join select all the rows from given tables and print the row of matching columns.
mysql> select * from Orders;
+---------+------------+------------+
| OrderID | CustomerID | OrderDate |
+---------+------------+------------+
| 10308 | 2 | 1996-09-18 |
| 10309 | 37 | 1996-09-19 |
| 10310 | 77 | 1996-09-20 |
| 10311 | 33 | 2011-10-11 |
+---------+------------+------------+
4 rows in set (0.01 sec)
mysql>
mysql> select * from Customers;
+------------+----------------------+----------------+---------+
| CustomerID | CustomerName | ContactName | Country |
+------------+----------------------+----------------+---------+
| 1 | Alfreds Futterkiste | Maria Anders | Germany |
| 2 | Ana Trujillo Empared | Ana Trujillo | Mexico |
| 3 | Antonio Moreno Taque | Antonio Moreno | Mexico |
| 33 | paul | jany | India |
+------------+----------------------+----------------+---------+
4 rows in set (0.01 sec)
mysql>
Here, CustomerID is the matching column. The matching rown entries are "2" and "33". Below command of "INNER JOIN" will print the row containing matching colums.
mysql> select o.OrderID,c.CustomerName from Orders o INNER JOIN Customers c ON o.CustomerID=c.CustomerID;
+---------+----------------------+
| OrderID | CustomerName |
+---------+----------------------+
| 10308 | Ana Trujillo Empared |
| 10311 | paul |
+---------+----------------------+
2 rows in set (0.01 sec)
mysql>
You can get a complete row list for matching column from the below query.
mysql> select o.OrderID,o.CustomerID,o.OrderDate,c.CustomerID,c.CustomerName,c.ContactName,c.Country from Orders o INNER JOIN Customers c ON o.CustomerID=c.CustomerID;
+---------+------------+------------+------------+----------------------+--------------+---------+
| OrderID | CustomerID | OrderDate | CustomerID | CustomerName | ContactName | Country |
+---------+------------+------------+------------+----------------------+--------------+---------+
| 10308 | 2 | 1996-09-18 | 2 | Ana Trujillo Empared | Ana Trujillo | Mexico |
| 10311 | 33 | 2011-10-11 | 33 | paul | jany | India |
+---------+------------+------------+------------+----------------------+--------------+---------+
2 rows in set (0.01 sec)
mysql>
mysql> select * from Orders;
+---------+------------+------------+
| OrderID | CustomerID | OrderDate |
+---------+------------+------------+
| 10308 | 2 | 1996-09-18 |
| 10309 | 37 | 1996-09-19 |
| 10310 | 77 | 1996-09-20 |
| 10311 | 33 | 2011-10-11 |
+---------+------------+------------+
4 rows in set (0.01 sec)
mysql>
mysql> select * from Customers;
+------------+----------------------+----------------+---------+
| CustomerID | CustomerName | ContactName | Country |
+------------+----------------------+----------------+---------+
| 1 | Alfreds Futterkiste | Maria Anders | Germany |
| 2 | Ana Trujillo Empared | Ana Trujillo | Mexico |
| 3 | Antonio Moreno Taque | Antonio Moreno | Mexico |
| 33 | paul | jany | India |
+------------+----------------------+----------------+---------+
4 rows in set (0.01 sec)
mysql>
Here, CustomerID is the matching column. The matching rown entries are "2" and "33". Below command of "INNER JOIN" will print the row containing matching colums.
mysql> select o.OrderID,c.CustomerName from Orders o INNER JOIN Customers c ON o.CustomerID=c.CustomerID;
+---------+----------------------+
| OrderID | CustomerName |
+---------+----------------------+
| 10308 | Ana Trujillo Empared |
| 10311 | paul |
+---------+----------------------+
2 rows in set (0.01 sec)
mysql>
You can get a complete row list for matching column from the below query.
mysql> select o.OrderID,o.CustomerID,o.OrderDate,c.CustomerID,c.CustomerName,c.ContactName,c.Country from Orders o INNER JOIN Customers c ON o.CustomerID=c.CustomerID;
+---------+------------+------------+------------+----------------------+--------------+---------+
| OrderID | CustomerID | OrderDate | CustomerID | CustomerName | ContactName | Country |
+---------+------------+------------+------------+----------------------+--------------+---------+
| 10308 | 2 | 1996-09-18 | 2 | Ana Trujillo Empared | Ana Trujillo | Mexico |
| 10311 | 33 | 2011-10-11 | 33 | paul | jany | India |
+---------+------------+------------+------------+----------------------+--------------+---------+
2 rows in set (0.01 sec)
mysql>