标题: 多表倒序查询 [打印本页] 作者: 若叶花吹雪 时间: 2010-1-10 02:17 标题: 多表倒序查询 这个多表查询每个表都能够按顺序把前两条数据查询出来,但我想每一个表查询都能按倒序排出来,那样每一个表更新的数据就能显示出来,按ID字段倒序排列,那个高手帮忙一下
rs.open"Select TOP 2 * from _xinwen union all Select TOP 2 * from _tiyu union all Select TOP 2 * from _yule union all Select TOP 2 * from _xiaohua union all Select TOP 2 * from _jiaocheng ",conn,1,1作者: bgag 时间: 2010-1-10 02:17
这样可以做到:先在每个表中查询最后更新的记录(两条)
最后再将多个表组合成一个新表 as t,然后再在外层排列
dim orderby:orderby=" order by id desc "
dim sql
sql=" select * from ("
sql=sql=&" Select TOP 2 * from _xinwen "&orderby
sql=sql=&" union all"
sql=sql=&" Select TOP 2 * from _tiyu ""&orderby
sql=sql=&" union all "
sql=sql=&" Select TOP 2 * from _yule ""&orderby
sql=sql=&" union all "
sql=sql=&" Select TOP 2 * from _xiaohua ""&orderby
sql=sql=&" union all "
sql=sql=&" Select TOP 2 * from _jiaocheng ""&orderby
sql=sql=&") as t "
sql=sql=&" order by id desc "作者: 龙龙 时间: 2010-1-10 02:18
最后一个表查询放上 order by ID desc 就行了,不要每个上面都放作者: 陈君 时间: 2010-1-10 02:18
我试过了是不行的啊作者: 酷aiq兒kuku 时间: 2010-1-10 02:18
后面直接加 order by ID desc 不行吗?作者: ︶ㄣ⒏懂緈諨 时间: 2010-1-10 02:18
我觉得要在每个select后面加order by id desc的