首先你这个users_table 的ID字段最好设置成主键,其次其他所有表里的ID都需要有索引,这样才能保证速度。
select * from user_table a where
exists (select 1 from sub_table1 b where b.id = a.id )
or
exists (select 1 from sub_table2 c where c.id = a.id )
......
你应该这样:
select *from users_table a,users_table1 b,users_table2 c
where a.id=b.id=c.id
其中users_table1、users_table2是你的其他表部分
你还在吗?问题解决没有?
既然遇到问题怎么不回我的话?这样我怎么帮你解决呢?朋友!
创建视图应该是最快的:
create view vtest
as
select id from 其他表1
union
select id from 其他表2
...
go
--查询
select *
from user_table a inner join vtest b on a.id=b.id
go
应该在WHERE条件中加入几个表之间以ID编号的相关连接再SELECT