关于在myeclipse中执行mySQL语句出现问题

 

之前我第一次发帖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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值