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
Preface To solve the single point of failure, we ...
I am planning to build my own website, so I took ...
Table of contents Preface Enumerable properties I...
All-round system monitoring tool dstat dstat is a...
As we all know, the web pages, websites or web pag...
This article mainly introduces the example analys...
This article example shares the specific code of ...
Let's take a look at the problem of VScode re...
This is because the database server is set to aut...
Generate SSL Key and CSR file using OpenSSL To co...
Table of contents 1. What is Promise? 2. Why is t...
Margin of parallel boxes (overlap of double margi...
Table of contents 1. Objectives 2. Environmental ...
First, check whether the hard disk device has a d...
Copy code The code is as follows: <style> ....