


What is the difference between inner join, left outer join, right outer join and cross join?
The difference between inner joins, left outer joins, right outer joins, and cross joins

Figure 1: Table A data
The structure of table B is as follows: Bid: int; identification seed, primary key, auto-increment ID Bnameid: int The data situation, that is, the record situation using select * from B is as follows Shown in Figure 2:

Figure 2: Table B data
In order to distinguish Bid and Aid, we do not allow everyone to have Misunderstanding, so set the starting seed of Bid to 100. Anyone with basic knowledge of SQL knows that to connect two tables, there must be a connection field. From the data in the above table, we can see that Aid in table A and Bnameid in table B are two connection fields. . Figure 3 below illustrates the relationship between all connected record sets:

Figure 3: Connection diagram
Now we connect internally and outer joins are explained one by one. 1. Inner join: Use inner join to obtain the records of the common part of the two tables, that is, the record set C in Figure 3. The statement is as follows: Select * from A JOIN B ON A.Aid=B.Bnameid. The running result is as shown in Figure 4. As shown: In fact, the operation results of select * from A,B where A.Aid=B.Bnameid and Select * from A JOIN B ON A.Aid=B.Bnameid are the same.

Figure 4: Inner join data
2. Outer join: There are two types of outer joins, one is left join (Left JOIN) and right join (Right JOIN)
(1) Left join (Left JOIN): that is, the public part record set C + table A record set A1 in Figure 3.
The statement is as follows: select * from A Left JOIN B ON A.Aid=B.Bnameid
The running results are shown in Figure 5 below:

Figure 5: Left join data
Explanation: In the statement, A is on the left side of B, and it is a Left Join, so the operation method is: A left join B records = Figure 3 public part record set C + table A record set A1
In Figure 3, that is, the Aid that exists in record set C is: 2 3 6 7 8
In Figure 1, that is, the Aid that exists in all record sets A of table A is: 1 2 3 4 5 6 7 8 9
The Aid that exists in the record set A1 of table A=(In Figure 1, it is all the Aid in table A)-(In Figure 3, it is the Aid that exists in the record set C). The final result is: 1 4 5 9
From this, we can conclude that the records of A left connected to B in Figure 5 = the public part record set C in Figure 3 + the record set A1 of table A. The final result can be seen in Figure 5 that Bnameid and Bid are not NULL. The records are all in the record set C in the public part of Figure 3; the four records with Bnameid and Bid as NULL and Aid as 1 4 5 9 are the Aids that exist in the record set A1 of table A.
(2) Right JOIN: That is, the public part record set C in Figure 3 + the record set B1 of table B.
The statement is as follows: select * from A Right JOIN B ON A.Aid=B.Bnameid The running result is shown in Figure 6 below:
Figure 6: Right join data
Description: In the statement, A is to the left of B and is a Right Join, so the operation method is: A right join B records = Figure 3 public part record set C + table B record set B1
In Figure 3, the Aid that exists in record set C is: 2 3 6 7 8
In Figure 2, the Bnameid that exists in all record sets B of table B is: 2 3 6 7 8 11
Table The Bnameid that exists in the B record set B1 = (in Figure 2, that is, all the Bnameids in the B table) - (in Figure 3, that is, the Aid that exists in the record set C). The final result is: 11
This leads to Figure 6 The records of the right connection of A in B = the public part record set C in Figure 3 + the table B record set B1. The final result can be seen in Figure 6 that the non-NULL records of Aid and Aname are all in the public part record set C of Figure 3. Record; the record with Aid and Aname as NULL and Aid as 11 is the Bnameid that exists in the record set B1 of table B.
Cross connection: When two tables are joined without conditions, the number of entries = Figure 1 * Figure 2
The above is the detailed content of What is the difference between inner join, left outer join, right outer join and cross join?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











After updating to the latest win11 system, many users are not sure how to connect the controller to play games. For this reason, we have brought you a detailed tutorial on connecting the win11 controller today. If you haven't completed the connection yet, let's take a look at how to operate it. . How to connect the controller in win11: 1. Click Start below and then enter Windows Settings to open the "Control Panel". 2. After entering, you can find "View devices and printers" to enter. 3. At this point you can see the information about the controller device and just make the connection. 4. After the connection is successful, a √ appears, and the connection is completed.

In order to make sure your network connection is working properly or to fix the problem, sometimes you need to check the network connection details on Windows 11. By doing this, you can view a variety of information including your IP address, MAC address, link speed, driver version, and more, and in this guide, we'll show you how to do that. How to find network connection details on Windows 11? 1. Use the "Settings" app and press the + key to open Windows Settings. WindowsI Next, navigate to Network & Internet in the left pane and select your network type. In our case, this is Ethernet. If you are using a wireless network, select a Wi-Fi network instead. At the bottom of the screen you should see

Many times we need to use a computer to connect to the printer for various printing operations, but sometimes some users will encounter the problem that win7 cannot connect to the printer 0x0000011b. The following is the specific solution. win7 cannot connect to the printer 0x0000011b1. Shortcut key "win+r", enter "regedit" 2. Find the following path "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print" 3. Right-click to create a new value "DWORD (32-bit) value (D) and Set the value to 0. Name the new project "RpcAuthnLevelPri

How to connect the keep body fat scale? Keep has a specially designed body fat scale, but most users do not know how to connect the keep body fat scale. Next is the graphic tutorial on the connection method of the keep body fat scale that the editor brings to users. , interested users come and take a look! How to connect the keep body fat scale 1. First open the keep software, go to the main page, click [My] in the lower right corner, and select [Smart Hardware]; 2. Then on the My Smart Devices page, click the [Add Device] button in the middle; 3 , then select the device you want to add interface, select [Smart Body Fat/Weight Scale]; 4. Then on the device model selection page, click the [keep body fat scale] option; 5. Finally, in the interface shown below, finally [Add Now] at the bottom

When you use the Edge browser to access web pages, have you ever encountered a prompt that your connection is not a dedicated connection, causing web browsing to fail? How is this going? Many friends don’t know how to deal with this problem. You can take a look at the following three solutions. Method 1 (simple and crude): In the edge browser, you can try to solve the problem of the website being inaccessible by entering the settings and turning off the security function, and then blocking location permissions in the website permissions. It is important to note that the effectiveness and duration of this approach may vary, and specific effects cannot be determined. After restarting your browser, you can try visiting the website to see if the issue is resolved. Method 2: Adjust the keyboard to English input

Solutions to Restricted Network Connections in Win10 With the rapid development of technology, the Internet has become an indispensable part of people's lives. However, sometimes we may encounter some problems when connecting to the Internet on computers using the Windows 10 operating system, one of which is restricted connections. In this case, we cannot access web pages, download files, or use network functions normally. So, is there any way to solve this problem? This article will introduce you to several common solutions. 1. Check the network connection settings. First, I

What does 0x0000011b mean when connecting to a printer? Users often encounter various error codes when using computers, laptops or other devices. Among them, 0x0000011b is a common printer connection error code. So, what does connecting printer 0x0000011b mean? First, we need to understand the basic principles of printer connection. When we need to print files from the computer, we usually need to connect the printer to the computer for data transfer between the two. This connection can be made via

With the development of the digital era, shared printers have become an indispensable part of the modern office environment. However, sometimes we may encounter the problem that the shared printer cannot be connected to the printer, which will not only affect work efficiency, but also cause a series of troubles. This article aims to explore the reasons and solutions for why a shared printer cannot connect to the printer. There are many reasons why a shared printer cannot connect to the printer, the most common of which is network issues. If the network connection between the shared printer and the printer is unstable or interrupted, normal operation will not be possible.
