SQL from zero to quickly mastering "table join query"

Source: Internet
Author: User

Look at these table connections, personal feeling ' left outer connection ', ' right outer connection ' and ' full outer connection ' application is OK.

1. External connection

(1) LEFT join: Returns records that include all records in the left table and the connection fields in the right table.

In the student table and the Stu-detail table, query the student number and the city of residence with the same ID, as in the following statement.

Use test

SELECT student.s_id,stu_detail.addr

From student left OUTER JOIN stu_detail

On student.s_id=stu_detail.s_id;

(2) Right join: The right table takes all, the left table picks out and the right table has the same identified data.

In the student table and the Stu_detaiil table, query the student name and correspondence number with the same ID, including the students who did not fill in the name, with the following statement

Use test

SELECT student.name,stu_detail.s_id--The first line shows what data to take

From student right OUTER join Stu_detail--second row description table connection

on student.s_id = stu_detail.s_id; --The third line describes the conditions of the connection, usually the ID is equal

2. Full-Outer connection

A full outer join, also known as a full outer join, returns all the record data in two connections.

In the student table and the Stu_detail table, use the full outer join query, as in the following statement.

Use test

SELECT student.name,stu_detail.addr

From student full OUTER JOIN Stu_detail

on student.s_id = stu_detail.s_id;

SQL from zero to quickly mastering "table join query"

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.