select * from tb1 where id in (select id from tb2)太慢,有什么方法可以取代 in
同上
[解决办法]
select tb1.* from tb1 join tb2 on tb1.id=tb2.id
[解决办法]
用连接
select a.* from tb1 a inner join tb2 b on a.[id]=b.[id]
[解决办法]
用EXISTS来代替IN,特别是对于从表数据量较大的情况下:
SELECT A.* FROM TAB1 A WHERE EXISTS(SELECT B.ID FROM TB2 B WHERE B.ID=A.ID)
[解决办法]
in 会引起全表扫描,用不到索引,所以会很慢,用 inner join 吧