Home > PL/SQL > [PLSQL] How to Join on top (First) row

[PLSQL] How to Join on top (First) row

Wednesday, 26 August, 2009 Leave a comment Go to comments

SELECT *
  FROM (SELECT ROWNUM t FROM DUAL CONNECT BY LEVEL < 6)
  JOIN (SELECT v, ROW_NUMBER() OVER(PARTITION BY v ORDER BY 1) rwnm
                     FROM (SELECT 1 v
                              FROM DUAL
                            UNION ALL
                            SELECT 1 FROM DUAL
                            UNION ALL
                            SELECT 2 FROM DUAL)) ON t = v
                                                    AND rwnm = 1;
Advertisements
Categories: PL/SQL Tags: ,
  1. Monday, 25 January, 2010 at 12:05 pm

    key value

    ROW_NUMBER() OVER(PARTITION BY generatorcode ORDER BY 1) rwnm

    AND rwnm = 1;

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: