开发者

Union of two queries with the first query resultset getting the first ten rownums in Oracle

开发者 https://www.devze.com 2023-02-26 12:41 出处:网络
I want Union of two queries with the first query resultset getting the开发者_运维问答 first ten rownums in Oracle.

I want Union of two queries with the first query resultset getting the开发者_运维问答 first ten rownums in Oracle. Example: Like if first query has 10 rows and max rownum is 10.I want second query rownum to be started from 11 in the result of union.


SELECT  *
FROM    (
        SELECT  *
        FROM    table1
        ORDER BY
                col1
        )
WHERE   rownum <= 10
UNION ALL
SELECT  *
FROM    (
        SELECT  *, rownum AS rn
        FROM    (
                SELECT  *
                FROM    table2
                ORDER BY
                        col2
                )
        )
WHERE   rn > 10
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号