「Oracle」rownumを指定してトップ行の結果を抽出するサンプル
書式
SELECT * FROM テーブル名 WHERE ROWNUM <=XXX
使用例
SELECT
*
FROM
(
SELECT
*
FROM
TEST_TABLE1
ORDER BY
AGE DESC
)
WHERE
ROWNUM <= 3
SELECT
*
FROM
(
SELECT
*
FROM
TEST_TABLE1
ORDER BY
AGE DESC
)
WHERE
ROWNUM <= 3
SELECT * FROM ( SELECT * FROM TEST_TABLE1 ORDER BY AGE DESC ) WHERE ROWNUM <= 3
結果
AGE USERNAME
32 user001
28 user002
25 user003