sql 查询多张表

[复制链接]
查看11 | 回复4 | 2013-7-15 13:09:12 | 显示全部楼层 |阅读模式
追不到800分的。300顶了方法很多,asp 把13张表的表名放到数组里,再循环这个数组,动态生成SQL查询,sqlstr ="select top 30* from " & tbname(i) & " order by orderid"如果用一句SQL查询得到的话select top 30 * from tb1 order by orderid union all select top 30* from tb2 order by orderid union all ....union allselect top 30 from tb13 order by orderid 另外不明白你是前30条记录是什么意思,上面写的是每个表的前30条,如果合...
回复

使用道具 举报

千问 | 2013-7-15 13:09:12 | 显示全部楼层
建个视图不就完事了吗?SELECT TOP 30 *FROM [table1]UNION select top 30 * from [table2] UNION select top 30 * from [table3] ……当然,如果你所有表的内容是一样的话,这个是出不来效果的,只会把不同的结果显示出来。 然后你在 select * from ...
回复

使用道具 举报

千问 | 2013-7-15 13:09:12 | 显示全部楼层
left untion on ,union on 你把所有的表连接起来,再使用 order by date DESC 或者ASC...
回复

使用道具 举报

千问 | 2013-7-15 13:09:12 | 显示全部楼层
ASP的?什么数据库啊?...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行