Zzz助 2016-05-10 05:52 采纳率: 20%
浏览 1802
已结题

SQL嵌套查询语句的报错问题

String sql = "select * from msgInfo where ID in(select top 15 ID from msgInfo where chatRoom=? Order by chatTime DESC) order by chatTime";
String userName=session.getAttribute("_USER").toString();
PreparedStatement ps = conn.preparedStatement(sql);
ps.setString(1,session.getAttribute("_CHAT_ROOM").toString());
ResultSet rs = conn.executeQuery();

这语句有问题吗,怎么老报错,没道理啊

ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '15 ID from msgInfo where chatRoom='dragon inn' Order by chatTime DESC) order by ' at line 1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '15 ID from msgInfo where chatRoom='dragon inn' Order by chatTime DESC) order by ' at line 1

  • 写回答

6条回答

  • 此号已清理 2016-05-10 06:29
    关注

    一,Mysql 应该是不支持top关键词的,你应该用limit
    二.limit 关键词不能和 in 一起使用,所以你要在limit子查询外再嵌套一层子查询.

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序