sql数据库多表联合动态查询

现有info_200601,info_200602至info_20060X个表,其表是动态生成的,表结构相同,只是表名不同,请问如果用循环语句一次查出这些表中的内容,并以sn字段做降序
2026年09月20日 10:01
有2个网友回答
网友(1):

select * from (
select * from info_200601
union
select * from info_200602
union
.
.
. )
oder by sn desc

没有验证,不知道行不行

网友(2):

int j=X;//X<=9
string tbname="info_20060";
strSQL="";
strSQl+="select * from (select * from info_200601";
for(int i=2;istrSQL+=" union select * from "+ tbname + i.toString();
strSQL+=") order by sn desc";