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

MySQL sharding details

1. Business scenario introduction Suppose there i...

Summary of methods for inserting videos into HTML pages

Now if you want to use the video tag in a page, y...

Solve the problem of no my.cnf file in /etc when installing mysql on Linux

Today I wanted to change the mysql port, but I fo...

How to add a disk in Vmware: Expand the disk

This article describes how to add or expand a dis...

Detailed explanation of common MySQL operation commands in Linux terminal

Serve: # chkconfig --list List all system service...

Vue implements tab label (label exceeds automatic scrolling)

When the created tab label exceeds the visible ar...

Click the toggle button in Vue to enable the button and then disable it

The implementation method is divided into three s...

CSS3 realizes various graphic effects of small arrows

It’s great to use CSS to realize various graphics...

A brief discussion on common operations of MySQL in cmd and python

Environment configuration 1: Install MySQL and ad...

Docker Tutorial: Using Containers (Simple Example)

If you’re new to Docker, take a look at some of t...

mysql 5.7.11 winx64.zip installation and configuration method graphic tutorial

Install and configure the MySql database system. ...

Example of how to mosaic an image using js

This article mainly introduces an example of how ...