mysql全外和交叉&&sql92pksql99
阿新 • • 發佈:2020-07-08
#全外
use girls;
SELECT b.*,a.*
FROM beauty b
FULL OUTER JOIN boys a
on b.boyfrien_id=a.id; #交叉連線99標準笛卡爾乘積
SELECT b.*,ob.*
FROM beauty b
CROSS JOIN boys ob; #sql92和sql99pk
#功能:sql99支援的較多
#可讀性:sql99實現連線條件和篩選條件分離,可讀性較高 #一、查詢編號>3的女神的男朋友資訊,如果有則列出詳細,如果沒有,用nu11填充、
SELECT b.id,b.name,be.*FROM beauty b
LEFT OUTER JOIN boys be
ON b.boyfriend_id=be.id
and b.id>3; #二、查詢哪個城市沒有部門
USE myemployees;
SELECT city
FROM locations l
LEFT OUTER JOIN departments d
on d.location_id=l.location_id
WHERE d.department_id is null; #三、查詢部門名為SAM或IT的員工資訊
SELECT e.*,d.department_name
FROM employees eLEFT OUTER JOIN departments d
on e.department_id=d.department_id
WHERE d.department_name in('SAL','IT');