select * from (
select id from table1
union all
select id from table2
union all
select id from table3
union all
select id from table4
union all
select id from table5
union all
select id from table6
union all
select id from table7
) as temp WHERE xx= xx;
我这样查询是不是本身就是不正确的?
是有点问题,你这个union 7个表,尽量让每个子查询走索引,应该会快些,可以看看执行计划, 瓶颈应该在每个子查询上,union all 本身不耗什么时间的 ------解决方案--------------------
select * from (
select id from table1
union all
select id from table2
union all
select id from table3
union all
select id from table4
union all
select id from table5
union all
select id from table6
union all
select id from table7