结合三个选择查询?

时间:2011-01-27 03:32:53

标签: mysql

我想结合这三个sql查询

SELECT homeupload, COUNT(*) FROM link GROUP BY homeupload
SELECT mediaType, COUNT(*) FROM link GROUP BY mediaType
SELECT emailSub, COUNT(*) FROM link WHERE emailSub='1' GROUP BY emailSub

进入单个查询。这可能吗?

1 个答案:

答案 0 :(得分:4)

尝试使用UNION

SELECT homeupload, COUNT(*) FROM link GROUP BY homeupload
UNION 
SELECT mediaType, COUNT(*) FROM link GROUP BY mediaType
UNION 
SELECT emailSub, COUNT(*) FROM link WHERE emailSub='1' GROUP BY emailSub

Reference