当前位置:网站首页>MySQL (IX)

MySQL (IX)

2022-06-11 10:43:00 wxxxx_ xx

SQL92 use + Resolve external connections , But in SQL92 There is no full external connection inside .

SQL99 Use JOIN ON Statement to solve the outer connection .

Oracle Yes SQL92 Better support , Can also be used SQL99, and MySQL Only use SQL99 Make external connections

but MySQL I won't support it SQL99 Use FULL JION Make full external connection .

UNION The operator

UNION Operator returns the union of the result sets of two queries , Remove duplicate records

UNION ALL The operator

UNION ALL Operator returns the union of the result sets of two queries . For duplicate parts of two result sets , No weight removal .

 

7 Kind of JOIN The implementation of the

Internal connection

Inquire about A Map and B There are data in the figure

SELECT employee_id,department_name
FROM employee e JOIN departments d
ON e.'employee_id'=d.'department_name';

 

 

The left outer join

Inquire about A There is , however B Tuliwei NULL.

and A Map and B There are records in the picture .

Top left

SELECT employee_id,department_name
FROM employee e LEFT JOIN departments d
ON e.'employee_id'=d.'department_name';

Right connection

Inquire about B There is , however A Tuliwei NULL.

and A Map and B There are records in the picture .

SELECT employee_id,department_name
FROM employee e RIGHT JOIN departments d
ON e.'employee_id'=d.'department_name';

 

A⊕ B

Only query A There is ,B The data in the figure is NULL The record of

SELECT employee_id,department_name
FROM employee e LEFT JOIN departments d
ON e.'employee_id'=d.'employee_id'
WHERE d.'department_name' IS NULL;

 B⊕ A

  Only query B There is ,A The data in the figure is NULL The record of

SELECT employee_id,department_name
FROM employee e RIGHT JOIN departments d
ON e.'employee_id'=d.'employee_id'
WHERE e.'department_name' IS NULL;

 

  Full outer join

 

Query... In two tables A And B matching ,A Mismatch B,B Mismatch A The data of

 (MYSQL,SQL99) Method 1 : The left outer join ( Right connection ) and  B⊕ A(A⊕ B) Two part use UNION ALL sentence

SELECT employee_id,department_name
FROM employee e LEFT JOIN departments d
ON e.'employee_id'=d.'department_name';
UNION ALL
SELECT employee_id,department_name
FROM employee e RIGHT JOIN departments d
ON e.'employee_id'=d.'employee_id'
WHERE e.'department_name' IS NULL;

(Oracle,SQL99) Method 2 :FULL JOIN sentence  

SELECT employee_id,department_name
FROM employee e FULL JOIN departments d
ON e.'employee_id'=d.'department_name';

(A⊕ B) ∪ (B⊕ A) 

 

SELECT employee_id,department_name
FROM employee e LEFT JOIN departments d
ON e.'employee_id'=d.'employee_id'
WHERE d.'department_name' IS NULL;
UNION ALL
SELECT employee_id,department_name
FROM employee e RIGHT JOIN departments d
ON e.'employee_id'=d.'employee_id'
WHERE e.'department_name' IS NULL;

 

原网站

版权声明
本文为[wxxxx_ xx]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111033289266.html