Left outer join will return all records in the left table and records equal to the join field in the right table; if there is no data in the right table, it will be null. A right outer join will return all records in the right table that are equal to the join fields in the left table; null if there is no data in the left table. A full outer join will return all records in the left and right tables that are equal to the join fields in the left and right tables.
In SQL, outer joins include left join (left join), right join (right join), and full outer join (full join).
Left outer join (left join): Returns all records in the left table that are equal to the join fields in the right table.
Right outer join (right join): Returns all records in the right table that are equal to the join fields in the left table.
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.
First put two tables, one student table; one grades table
# #Left outer join
will return all rows from the right table. If a row in the left table does not have a matching row in the right table, a null value will be returned for the right table. Left join: select *from Student LEFT JOIN Score ON Student.s_id=Score.s_idWith the left table as In the main table, the right table has no data and is nullRight outer join
will return all the rows in the right table. If a row in the right table does not have a matching row in the left table, a null value will be returned for the left table;The right table is the main table, and if there is no data in the left table, nullselect *from Student right JOIN Score ON Student.s_id=Score.s_id
Full outer join (FULL JOIN or FULL OUTER JOIN)
Full outer join returns all rows in the left and right tables. When a row has no matching row in another table, the other table's select list column contains null values. If there are matching rows between tables, the entire result set row contains the data values from the base table.select *from Student full JOIN Score ON Student.s_id=Score.s_id select *from Student full outer JOIN Score ON Student.s_id=Score.s_idRelated recommendations: "
SQL Tutorial"
The above is the detailed content of How to differentiate between left outer join, right outer join and full outer join?. For more information, please follow other related articles on the PHP Chinese website!