日期:2014-05-20  浏览次数:20728 次

大家帮我看看这个那里错了谢谢!!
这个sql语句那里错了?
Java code

  String sql = "select " +
                         "thread.id, " +
                         "thread.title, " +
                         "(select count(id) from comment where thread=thread.id) as reply, " +
                         "(select username from user where id=thread.user) as author, " +
                         "thread.hit, " +
                         "(select top 1 create_time from comment where comment.thread=thread.id order by create_time desc) as create_time, " +
                         "(select top 1 user.username from comment,user where comment.thread=thread.id and comment.user=user.id order by create_time desc) as user " +
                         "from thread" +
                         "order by user desc";



------解决方案--------------------
MySql不支持top,应使用limit。如果想要第一条记录,可以使用limit 0,1
例如,select user_name from users order by user_id desc limit 0,1
------解决方案--------------------
这里出错了"from thread" + "order by user desc";
少了空格,=〉" from thread " + " order by user desc";

------解决方案--------------------
你直接System.out.println(sql),看看不就知道了嘛,这个还不简单
------解决方案--------------------
探讨
MySql不支持top,应使用limit。如果想要第一条记录,可以使用limit 0,1
例如,select user_name from users order by user_id desc limit 0,1