我的数据库(ACCESS)有几个表中(结构相同),我想选择出每个表中最新加入的一条记录(add_date字段可以判断)我要下面的方法:
select_newinfo = "select * from (select top 1 title,infoid from info_gonggao union all select top 1 title,infoid from info_shenghuo union all select top 1 title,infoid from info_canyin )"但选择出的记录却不是最新的。
我想应该是缺乏按时间排序,但是这样:
select_newinfo = "select * from (select top 1 title,infoid from info_gonggao ORDER BY add_date DESC union all select top 1 title,infoid from info_shenghuo ORDER BY add_date DESC union all select top 1 title,infoid from info_canyin ORDER BY add_date DESC )"虽然加了 ORDER BY add_date DESC,但却报错!!!
请问这条语句应该怎么写才正确???
select_newinfo = "select * from (select top 1 title,infoid from info_gonggao union all select top 1 title,infoid from info_shenghuo union all select top 1 title,infoid from info_canyin )"但选择出的记录却不是最新的。
我想应该是缺乏按时间排序,但是这样:
select_newinfo = "select * from (select top 1 title,infoid from info_gonggao ORDER BY add_date DESC union all select top 1 title,infoid from info_shenghuo ORDER BY add_date DESC union all select top 1 title,infoid from info_canyin ORDER BY add_date DESC )"虽然加了 ORDER BY add_date DESC,但却报错!!!
请问这条语句应该怎么写才正确???
解决方案 »
- 急!GridView数据导出Excel数据重复一半!!
- 留言板报错-必须声明标量变量 "@username"。
- c++怎么访问WCF接口
- 求助关于在asp.net里调用ocx控件
- 在DataGrid中如何在页面跳转时保存用户选择的值
- 如何在Datagrid中加入Dropdownlist,以便对数据集进行动态的过滤,谢谢
- 救命那!关于treeview。在我的机器可以用,为什么有个别人访问就提示tree.htc脚本找不到 ?!
- asp.net入门问题
- ViewState为什么在Repeater数据绑定之后会失效
- 求教,datagrid里一模板列内含dropdownlist
- ASP.NET中怎么用VB语言实现从数据库中读取保存在内的图片?
- 怎样判断GridView是否处于编辑状态?
使用union时,order by 语句只能在最后一个子句末尾出现
top 1 order by id desc 不就可以了
那请问选择数据库中的"最后一条记录",该怎么写?用什么关键字是最后一条记录?谢谢
-------------------------------------
前面我已经写好了
最大的记录。
另外“menuvb(戏子……年少,轻狂,不张扬)”朋友的方法也没实现(报错):
select_newinfo = "select * from (select top 1 title,infoid from info_gonggao union all select top 1 title,infoid from info_shenghuo union all select top 1 title,infoid from info_canyin ORDER BY add_date DESC)"
select top 1 title,infoid from info_shenghuo ORDER BY add_date DESC union all
select top 1 title,infoid from info_canyin ORDER BY add_date DESC
----------------------------
不需要 Select* from 直接 union all
如果要用 就把 SELECT * FROM 改成 SELECT title,infoid FROM
稍微改一下不就行了