之前我第一次发帖csdn,在网友的热心帮助下解决了问题
在myeclipse执行mssql
String sql = "select top 10 * from topic where boardId=" + boardId
+ " and topicId not in(select top " + rowBegin
+ " topicId from topic where boardId=" + boardId
+ " order by publishTime desc)order by publishTime desc";这是SQL是可以通过
可以通过,那要改写成mysql数据库的语法如下代码所示:
int startCount = 0;
int pageSize = 10;
if (page > 1) {
startCount = 10 * (page - 1);
}
String sql = "select * from topic order by publishTime desc limit "
+ startCount
+ ","
+ pageSize
+ " where boardId="
+ boardId+" and topicId not in(select topicId from tpoic order by publishTime desc limit " + startCount
+ "," + pageSize + "where boardId="+ boardId +")";
上面的代码有什么问题呢,在mysql里面怎么执行出来总是报这样的错
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where boardId=8 and topicId not in(select topicId from tpoic order by publishTim' at line 1
我传入的boardId是8。
遇到的问题有
This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
搜索得到的信息是
在MySQL4.1中子查询是不能使用LIMIT的,手册中也明确指明 “This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’ ”
这样的语句是不能正确执行的。
select * from table where id in (select id from table limit 10);
但是,只要你再来一层就行。如:
select * from table where id in (select t.id from (select * from table limit 10)as t)
ok这样就可以绕开limit子查询的问题。
最后调试为
select * from topic
where boardId=8 and topicId
not in(select topicId from(select * from topic
where boardId=8 order by publishTime desc limit 0)as t)
order by publishTime desc limit 10;