SQL JOIN keyword usage

Source: Internet
Author: User
Tags database join

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.