The difference between mysql outer join and inner join query

The difference between mysql outer join and inner join query

The syntax for an outer join is as follows:

SELECT field name
FROM table name 1 LEFT|RIGHT|FULL| [OUTER] JOIN table name 2
ON table name 1. field name 1 = table 2. field name 2

Left Outer Join

The result set of the left outer join contains all records in the left table and the records in the right table that meet the join conditions. The column values ​​from the right table that do not meet the join conditions in the result set are null.

LEFT JOIN

Right Outer Join

A right outer join is the reverse of a left outer join. The result set of a right outer join includes all records in the right table and records in the left table that meet the join conditions. The column values ​​of the source and left tables that do not meet the join conditions in the result set are null.

Inner Join

The inner join query compares each row of table T1 with each row of table T2 and finds the combination that satisfies the join predicate. When the join predicate is satisfied, the matching rows in A and B are combined column-wise (side-by-side) into a single row in the result set.

Here are a few examples to explain in detail:

T1 table:

ID name
1 Secondary School
2 Zhang San
3 Li Si

T2 table:

ID occupation
1 student
2 teacher
4 headmaster

Inner join result:

SELECT T1.*,T2.*
FROM TI INNER JOIN T2
  ON A.Id=B.Id
Id name Id1 occupation
1 Secondary School 1 student
2 Zhang San 2 teacher

Left join result:

SELECT T1.*,T2.*
FROM TI LEFT JOIN T2
  ON A.Id=B.Id
Id name Id1 occupation
1 Secondary School 1 student
2 Zhang San 2 teacher
3 Li Si NULL NULL

Right join result:

SELECT T1.*,T2.*
FROM TI RIGHT JOIN T2
  ON A.Id=B.Id
Id name Id1 occupation
1 Secondary School 1 student
2 Zhang San 2 teacher
NULL NULL 4 headmaster

Summarize

This is the end of this article about MySQL outer join and inner join queries. For more relevant MySQL outer join and inner join query content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of MySQL database--multi-table query--inner join, outer join, subquery, correlated subquery
  • MySQL case analysis explains outer join syntax

<<:  Analysis of Facebook's Information Architecture

>>:  Detailed explanation of the relationship between React and Redux

Recommend

Docker installation and configuration command code examples

Docker installation Install dependency packages s...

Common failures and reasons for mysql connection failure

=================================================...

mysql show simple operation example

This article describes the mysql show operation w...

Implementation of nacos1.3.0 built with docker

1. Resume nacos database Database name nacos_conf...

Detailed explanation of how to install MariaDB 10.2.4 on CentOS7

CentOS 6 and earlier versions provide MySQL serve...

Detailed explanation of lazy loading and preloading of webpack

Table of contents Normal loading Lazy Loading Pre...

Docker deployment springboot project example analysis

This article mainly introduces the example analys...

Docker Machine in-depth explanation

Differences between Docker and Docker Machine Doc...

More elegant processing of dates in JavaScript based on Day.js

Table of contents Why use day.js Moment.js Day.js...

JavaScript to implement image preloading and lazy loading

This article shares the specific code for impleme...