SQL INNER JOIN keyword
The INNER JOIN keyword returns a row when there is at least one match in the table.
INNER JOIN keyword Syntax
SELECT column_name (s) from Table_name1inner JOIN table_name2 on Table_name1.column_name=table_name2.column_name
Note: INNER join is the same as join.
The original table (used in the example):
"Persons" table:
| id_p |
LastName |
FirstName |
Address |
| City
| 1 |
Adams |
John |
Oxford Street |
London |
| 2 |
Bush |
George |
Fifth Avenue |
New York |
| 3 |
Carter |
Thomas |
Changan Street |
Beijing |
"Orders" table:
| Id_o |
OrderNo |
id_p |
| 1 |
77895 |
3 |
| 2 |
44678 |
3 |
| 3 |
22456 |
1 |
| 4 |
24562 |
1 |
| 5 |
34764 |
65 |
INNER JOIN (INNER join) instance
Now, we want to list everyone's orders.
You can use the following SELECT statement:
SELECT Persons.lastname, Persons.firstname, Orders.ordernofrom personsinner JOIN Orderson persons.id_p=orders.id_ Porder by Persons.lastname
Result set:
| LastName |
FirstName |
OrderNo |
| Adams |
John |
22456 |
| Adams |
John |
24562 |
| Carter |
Thomas |
77895 |
| Carter |
Thomas |
44678 |
The INNER JOIN keyword returns a row when there is at least one match in the table. If the rows in "Persons" do not match in "Orders," the rows are not listed.
SQL Inner Join keyword