Difference: left join returns all records in the left table that are equal to the join field in the right table; right join returns all records in the right table and records that are equal to the join field in the left table; inner join Only return rows with equal join fields in the two tables; full outer joins return all records in the left and right tables and records with equal join fields in the left and right tables.
left join (left join, left outer join): Returns all records in the left table that are equal to the join fields in the right table.
right join (right join, right outer join): Returns all records in the right table that are equal to the join fields in the left table.
inner join (equivalent join or inner join): Only return rows with equal join fields in the two tables.
full join (full outer join): Returns all records in the left and right tables that are equal to the join fields in the left and right tables.
For example:
Three records:A table
id Name
1 Xiao Wang
2 Xiao Li
3
#Inner join: (Only matching rows from 2 tables can be displayed)select a.name,b.job from A a inner join B b on a.id=b.A_idOnly one record can be obtained:
小李 老师Left join: (The one on the left The table is not restricted)select a.name,b.job from A a left join B b on a.id=b.A_id
小王 null 小李 老师 小刘 nullRight join: (The table on the right is not restricted)
select a.name,b.job from A a right join B b on a.id=b.A_idTwo Records:
小李 老师 null 程序员Full external join: (no restrictions on the left and right tables)
select a.name,b.job from A a full join B b on a.id=b.A_idFour pieces of data
小王 null 小李 老师 小刘 null null 程序员Note: In SQL, outer joins include left join and right join, full outer join, and equal join (inner join), also called inner joins.
Related recommendations: "SQL Tutorial
"The above is the detailed content of What is the difference between left join, right join, inner join and full outer join?. For more information, please follow other related articles on the PHP Chinese website!