这个SQL语句这么写?

来源:百度知道 编辑:UC知道 时间:2024/07/01 03:20:51
select top 5 * from fzu_posts where fid=2 and fsw='ok' order by tid desc
查询MYSQL数据库前5条的内容,为什么出错了?
select * from fzu_posts where fid=2 and fsw='ok' order by tid desc
这样就可以执行了,但是是全部的内容。
我是ASP+MYSQL的··
连接数据库的代码是:
set db = server.createobject("adodb.connection")
db.Open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;DATABASE=bbs;USER=root;PASSWORD=123456;"

不排序也还是提示错误。。

我在CMD命令行下面运行 select top 1 * from fzu_posts; 也提示错误。。。。。去掉top 1 就可以了···

解决了···原来不能用top n这样的···要用limit n 就可以了· ··

select top 5 * from (select * from fzu_posts where fid=2 and fsw='ok' order by tid desc
)
这是因为sql 执行顺序是这样,一共是6个步骤(语法、语意...),具体忘记了

没错

top 5

有top的时候好像不能用排序,你试试
select top 5 * from (select * from fzu_posts where fid=2 and fsw='ok' order by tid desc)

没有错,top 可以和order by 一起用,而且经常用.