一个带子查询的update语句

update pw_threads a inner join (select *
from pw_threads A
where 5>(select count(*) from pw_threads where A.fid=fid and A.postdate<postdate))
 b set a.lastpost=(select lastpost from (select lastpost from pw_threads order by lastpost desc limit 0,1) a)+1

这段语句并没有语法错误,但是没有达到只更新子查询中限定的范围的作用,把整个pw_theads的所有记录全部都更新了
请问应该怎么改一下。

作者: btut2004   发布时间: 2011-05-11

SQL code
update pw_threads a inner join 
(select * from pw_threads A where 5>(select count(*) from pw_threads where A.fid=fid and A.postdate<postdate))  b 
set a.lastpost=(select lastpost from (select lastpost from pw_threads order by lastpost desc limit 0,1) a)+1
where .....

作者: rucypli   发布时间: 2011-05-11

有where 了,干嘛再弄一个where,而且要放在where中的就是子查询,因为mysql不支持在where中有子查询所以才放到inner join那里。

我发现我有两个表使用了别名a,把后一个改成了别名c,还是一样,不是别名问题

作者: btut2004   发布时间: 2011-05-11

要达到什么目的?举例说明

作者: wwwwb   发布时间: 2011-05-11

目的是找出所有板块最老的5个帖子,把他们的最后回复时间更新成最新,(也就是把最老的帖子提前到最前面)

我的方法是找出所有帖子的最后更新的那个lastpost,也就是最前面的一个帖子。
用这个时间+1就是比最新的帖子还新。

把最老的帖子的最后回复时间设置成比最新的帖子还新。

我先取出每个板块最老的5个帖子,进行更新。

pw_threads是phpwind论坛的主贴表,里面有id是自增字段,fid是版块id,lastpost是最后回复时间,
postdate是发帖时间,似乎我个语句里面不应该有postdate,和我要实现的目的无关

作者: btut2004   发布时间: 2011-05-11