# 注释
-- 注释
-- 高级查询
-- 连接查询
SELECT t1.`Name`,t2.Brand_Name FROM brand t2,car t1 -- 笛卡尔乘积
WHERE t2.Brand_Code = t1.Brand
-- 多表连接查询
SELECT t1.`Name`,t2.Brand_Name,t3.prod_name
FROM car t1
LEFT JOIN brand t2 ON t1.Brand = t2.Brand_Code
LEFT JOIN productor t3 ON t2.Prod_Code = t3.Prod_Code
-- 联合查询 字段数必须一样
SELECT `Name`,Price FROM car
UNION
SELECT Brand_Name,Brand_Memo FROM brand
-- 子查询
SELECT * FROM car
WHERE car.brand in
(SELECT Brand_Code FROM brand WHERE Prod_Code = ‘p001‘)
时间: 2024-11-03 22:06:12