Home  >  Article  >  Database  >  How to differentiate between left outer join, right outer join and full outer join?

How to differentiate between left outer join, right outer join and full outer join?

青灯夜游
青灯夜游Original
2020-07-21 15:05:0413959browse

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.

How to differentiate between left outer join, right outer join and full outer join?

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

How to differentiate between left outer join, right outer join and full outer join?

How to differentiate between left outer join, right outer join and full outer join?

# #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_id

With the left table as In the main table, the right table has no data and is null

How to differentiate between left outer join, right outer join and full outer join?

Right 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, null

select *from Student right JOIN Score ON Student.s_id=Score.s_id

How to differentiate between left outer join, right outer join and full outer join?

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_id

How to differentiate between left outer join, right outer join and full outer join?

Related 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more