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"