Sql 有没有比联合所有人都快的方法
在SQL中,我使用Sql 有没有比联合所有人都快的方法,sql,sql-server,Sql,Sql Server,在SQL中,我使用UNION ALL从不同的表中获取一些数据,但是获取结果需要很长时间。有没有一种更快的方法来实现这一点,而无需使用UNION 例如,查询如下所示: select * from table_1 where date between '20141001' and '20141020' UNION ALL select * from table_2 where date between '20141001' and '20141020'; 仅就以下几点评论: 考虑在
UNION ALL
从不同的表中获取一些数据,但是获取结果需要很长时间。有没有一种更快的方法来实现这一点,而无需使用UNION
例如,查询如下所示:
select *
from table_1
where date between '20141001' and '20141020'
UNION ALL
select *
from table_2
where date between '20141001' and '20141020';
仅就以下几点评论:
- 考虑在两个表的
列上添加索引date
- 指定列列表,而不是使用
*
- 仔细检查
列的数据类型:是date还是datetime?如果是datetime,你真的需要成为datetime吗date