The difference between left join and right join in sql: 1. Left join can retrieve data as long as there are records in the left table, while right join only has records in the right table; 2. Left join has left The data in the table is the baseline, and the right join is the reverse join of the left outer join.
The operating environment of this article: Windows 7 system, SQL Server 2019 version, Dell G3 computer.
The difference between left join and right join in sql:
1. The meaning is different
Left join: As long as there are records in the left table, the data will be can be retrieved, but the records on the right must be retrieved from the records on the left table.
Right join: Right join means that as long as there are records in the right table, the data can be retrieved.
2. Different usage
Right join is the opposite of left join. Left join A LEFT JOIN B. The data queried by the connection must be present in A, but may or may not be present in B. Inner join A INNER JOIN B, only the data that is also present in A and B can be queried.
3. NULL values are different
The left join is based on the data in the left table. If there is data in the left table and no data in the right table, the data in the left table will be displayed in the right table. The data is displayed as empty.
Right join is the reverse join of left outer join. All rows from the right table will be returned. If a row in the right table has no matching row in the left table, null will be returned for the left table.
Recommended (free): sqlserver
The above is the detailed content of What is the difference between left join and right join in sql. For more information, please follow other related articles on the PHP Chinese website!