MYSQL中的多类型查询及高级查询操作
时间:2021-07-01 10:21:17
帮助过:13人阅读
(1)连接查询
SELECT t1.`Name`,t2.Brand_Name FROM brand t2,car t1 -- 笛卡尔乘积
WHERE t2.Brand = t1.Brand
-- 多表连接查询
SELECT t1.`Name`,t2.Brand_Name,t3.prod_name
FROM car t1
LEFT JOIN brand t2
ON t1.Brand = t2.Brand
LEFT JOIN productor t3 ON t2.Prod = t3.Prod
(2) 联合查询 字段数必须一样
SELECT `Name`,Price FROM car
UNION
SELECT Brand_Name,Brand_Memo FROM brand
(3)子查询
SELECT * FROM car
WHERE car.brand in
(SELECT Brand FROM brand WHERE Prod = ‘p001‘)
MYSQL中的多类型查询及高级查询操作
标签:高级 多表 分组查询 取出 去掉 bsp avg group limit