Before we begin, we create two tables to demonstrate the JOIN types we will introduce. Create a table CREATE TABLE `tbl_dept` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `deptName` VARCHAR(30) DEFAULT NULL, `locAdd` VARCHAR(40) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; CREATE TABLE `tbl_emp` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(20) DEFAULT NULL, `deptId` VARCHAR(11) NOT NULL, PRIMARY KEY (`id`), KEY `fk_dept_id` (`deptId`) ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; Initialize Data Seven types of JOIN 1. A ∩ B SELECT < select_list > FROM TableA A INNER JOIN TableB B # TOTAL ON A.Key = B.Key 2. A ( = A ∩ B + A* ) SELECT < select_list > FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key 3. B ( = A ∩ B + B* ) SELECT < select_list > FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key 4. A* ( = A - A ∩ B ) SELECT < select_list > FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key # Main table is retained when ON WHERE B.Key IS NULL # Filter data in table A 5. B* ( = B - A ∩ B ) SELECT < select_list > FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key WHERE A.Key IS NULL 6. A ∪ B SELECT < select_list > FROM TableA A FULL OUTER JOIN TableB B ## FULL OUTER ON A.Key = B.Key is only supported by Oracle 7. A ∪ B - A ∩ B SELECT < select_list > FROM TableA A FULL OUTER JOIN TableB B ON A.Key = B.Key WHERE A.Key IS NULL OR B.Key IS NULL This is the end of this article about the seven MySQL JOIN types. For more information about MySQL join types, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: An example of how to implement an adaptive square using CSS
>>: Implementing timed page refresh or redirect based on meta
1. Use pseudo-classes to display half of the Bord...
In the course of work, you will encounter many ca...
I installed a virtual machine a long time ago, an...
The upload form with image preview function, the ...
Chinese characters cannot be input in lower versio...
I don't expect to be an expert DBA, but when ...
1. Analytical thinking 1. Eliminate the machine...
This article shares the specific code of JavaScri...
What is a memory leak? A memory leak means that a...
Table of contents origin Environmental Informatio...
Copy code The code is as follows: height:auto !im...
Project requirements: When you click a product tr...
Regarding the connection method between Java and ...
Table of contents 1 System Introduction 2 System ...