mysql union all与子查询结合效率对比
SELECT * FROM baidu_day_2014_1 WHERE account = 'xxx'
UNION ALL
SELECT * FROM baidu_day_2014_2 WHERE account = 'xxx'
UNION ALL
SELECT * FROM baidu_day_2014_3 WHERE account = 'xxx'
UNION ALL
SELECT * FROM baidu_day_2014_4 WHERE account = 'xxx'
SELECT * FROM (
SELECT * FROM baidu_day_2014_1
UNION ALL
SELECT * FROM baidu_day_2014_2
UNION ALL
SELECT * FROM baidu_day_2014_3
UNION ALL
UNION ALL
SELECT * FROM baidu_day_2014_2 WHERE account = 'xxx'
UNION ALL
SELECT * FROM baidu_day_2014_3 WHERE account = 'xxx'
UNION ALL
SELECT * FROM baidu_day_2014_4 WHERE account = 'xxx'
SELECT * FROM (
SELECT * FROM baidu_day_2014_1
UNION ALL
SELECT * FROM baidu_day_2014_2
UNION ALL
SELECT * FROM baidu_day_2014_3
UNION ALL
SELECT * FROM baidu_day_2014_4) t WHERE t.account = 'xxx'
总结:第二个sql效率太低了,都下班了还没查完呢,建议第一种写法