Oracle-ORA-00923: 未找到要求的FROM关键字-Oracle不支持TOP N查询

查询语句:


SELECT TOP 20 NWID, NWTITLE, NW, NWEDITTIME, NWIMG
  FROM YW_NEWS
 ORDER BY NWEDITTIME DESC

出错提示:Message = "ORA-00923: 未找到要求的 FROM关键字"

原因:Oracle不支持TOP N 查询方式,需要用order by和rownum结合实现

解决方法:


SELECT NWID, NWTITLE, NW, NWEDITTIME, NWIMG
  FROM (SELECT * FROM YW_NEWS ORDER BY NWEDITTIME DESC)
 WHERE ROWNUM <= 20
 ORDER BY ROWNUM ASC

你可能感兴趣的:(Orale,MySQL)