1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

How to fetch single record from every department?!

Discussion in 'SQL PL/SQL' started by Vicky, Mar 3, 2015.

  1. Vicky

    Vicky Forum Advisor

    Messages:
    261
    Likes Received:
    11
    Trophy Points:
    260
    Location:
    Chennai
    Hii,


    Cud U tel me, How to fetch single(any) record from every department from HR.EMPLOYEES, without using Rowid?!
     
  2. jagadekara

    jagadekara Forum Guru

    Messages:
    1,126
    Likes Received:
    145
    Trophy Points:
    1,805
    Location:
    Pulivendula
    You can display by using rownum
     
  3. Vicky

    Vicky Forum Advisor

    Messages:
    261
    Likes Received:
    11
    Trophy Points:
    260
    Location:
    Chennai
    Isn't possible without using Rowid?/
     
  4. krasnoslobodtsev_si

    krasnoslobodtsev_si Forum Genius

    Messages:
    626
    Likes Received:
    129
    Trophy Points:
    810
    Location:
    Russian Federation
    What means to recive one record to each department?

    "How to fetch single(any) record from every department from HR.EMPLOYEES," - to use analytics
     
  5. Vicky

    Vicky Forum Advisor

    Messages:
    261
    Likes Received:
    11
    Trophy Points:
    260
    Location:
    Chennai
    I just need a query to fetch 1 record from every departments.,/,
     
  6. krasnoslobodtsev_si

    krasnoslobodtsev_si Forum Genius

    Messages:
    626
    Likes Received:
    129
    Trophy Points:
    810
    Location:
    Russian Federation
    Analytic Functions


    for example :
    Code (SQL):

    WITH
    step1 AS
        (
        SELECT
            hr.* ,
            ROW_NUMBER() OVER (partition BY hr.deptno ORDER BY "your_order") rn
    FROM HR.EMPLOYEES hr
        )
    SELECT
         st1.*
    FROM
        step1 st1        
    WHERE
        st1.rn = 1    

     
     
    Vicky likes this.
  7. vprog

    vprog Active Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    55
    Location:
    Ghaziabad
    select * from HR.EMPLOYEES group by deptno;