SQL JOIN keyword usage
The JOIN keyword is used to query data from two or more tables. Some relations are listed in these tables.
Database JOIN
Keyword connection uses SQL statements to query data from two or more tables, and some relationships are listed in these tables.
Tables often involve the opposite key in the database.
A major key is the unique value of a column (or composite column) for each row. Each primary key value must be a unique table. The purpose of this operation is to bind data together. The entire table contains all the data that is not repeated 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 |
Note that the "P_Id" column is the key to taking a seat at "persons. 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 "order" 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 the person in the "person" table, instead of using their names.
Note that the "P_Id" column is above the relationship table between the two.
Joining different SQL statements
As we continue with this example, we will list the types of connections that can be used and their differences.
Join: rows return to the table at least one match.
Left join: returns the table from the left of all rows, even if no matching table exists.
Right join: returns all rows from the right table, even if there is no match in the left table
Full join: When a result is returned, the row contains a table in the competition.
Note: For reprint, please indicate that it is from www.111cn.cn/database/database.html