How to use the SQL JOIN keyword
Join keyword to query the data from two or more than two tables based on some of the relationships listed in these tables.
Database Join
keyword in a connection using SQL statements to query the data from two or more than two tables based on some of the relationships listed in these tables.
Tables often involve each other's keys in the database.
A major key is the column (or combination of columns) of a unique value for each row. Each primary key value must be unique on the table. The purpose of this is to bind the data together, the entire table, and not duplicate all the data on each table.
Look at the "person" table:
| p_id |
LastName |
FirstName |
| Address
| City
| 1 |
Hansen |
Ola |
TIMOTEIVN 10 |
Sandnes |
| 2 |
Svendson |
Tove |
BORGVN 23 |
Sandnes |
| 3 |
Pettersen |
Kari |
STORGT 20 |
Stavanger |
Please note that the "p_id" column is the main key in "people" seating. This means that no two rows can have the same p_id. P_ID distinguishes two people, even if they have the same name.
Next, we have the Orders table:
| o_id |
OrderNo |
p_id |
| 1 |
77895 |
3 |
| 2 |
44678 |
3 |
| 3 |
22456 |
1 |
| 4 |
24562 |
1 |
| 5 |
34764 |
15 |
Note that the "o_id" column is the primary key "order" table, and that the "p_id" column refers to people in the "People" table and does not use their names.
Note that the relationship table is above the "p_id" column.
Different SQL joins
as we continue with examples, we will list types of connections that can be used, and the differences between them.
Join: A row returns with at least one match in the table
Left connection: Returns all rows from the left table, even if there is no matching correct table
Right connection: Returns all rows from the right table, even if there is no match in the left table
Full connection: When returned, the row has a table in a race
Note: Reprint please indicate from www.111cn.net/database/database.html