sql从有序表中选择

时间:2014-03-25 07:30:49

标签: sql oracle

我想问一下有序表中的一些记录。

select * from table_name order by something desc limit 4;

这是错误消息(是'限制4'行):

ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:
Error at Line: 7 Column: 1

1 个答案:

答案 0 :(得分:2)

使用ROWNUM来限制查询返回的行数

http://docs.oracle.com/cd/B28359_01/server.111/b28286/pseudocolumns009.htm#SQLRF00255

select * 
  (SELECT * FROM table_name ORDER BY someval desc)
 WHERE ROWNUM < 5;