Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:57:26+00:00 2026-06-17T06:57:26+00:00

I have one stage table ‘ STAGE_TABLE ‘ which includes following values (columns are

  • 0

I have one stage table ‘STAGE_TABLE‘ which includes following values (columns are varchar2 except ids) –

+-------------------------------------------------------------------------------------------------------------------------
¦  STAGE_ID ¦ EMP_ID     ¦ ATTR1_OLD_VAL ¦ ATTR1_NEW_VAL ¦ ATTR2_OLD_VAL ¦ ATTR2_NEW_VAL ¦ ATTR3_OLD_VAL ¦ ATTR3_NEW_VAL ¦
¦-----------+------------+---------------+---------------+---------------+---------------+---------------+---------------¦
¦         1 ¦       E001 ¦ xyz           ¦ pqr           ¦ mmm           ¦ nnn           ¦ zzz           ¦ aaa           ¦
¦         2 ¦       E001 ¦               ¦               ¦               ¦               ¦               ¦               ¦
¦         3 ¦       E001 ¦ pqr           ¦ abc           ¦ xxx           ¦ yyy           ¦               ¦               ¦
¦         4 ¦       E002 ¦ aaa           ¦ ccc           ¦ bbb           ¦ ttt           ¦               ¦               ¦
¦         5 ¦       E002 ¦               ¦               ¦               ¦               ¦ fff           ¦ ppp           ¦
¦         6 ¦       E002 ¦               ¦               ¦ kkk           ¦ jjj           ¦               ¦               ¦
+-------------------------------------------------------------------------------------------------------------------------

I want to merge multiple rows from above table belonging to same employee into one –

+-------------------------------------------------------------------------------------------------------------
¦ EMP_ID     ¦ ATTR1_OLD_VAL ¦ ATTR1_NEW_VAL ¦ ATTR2_OLD_VAL ¦ ATTR2_NEW_VAL ¦ ATTR3_OLD_VAL ¦ ATTR3_NEW_VAL ¦
¦------------+---------------+---------------+---------------+---------------+---------------+---------------¦
¦       E001 ¦ pqr           ¦ abc           ¦ xxx           ¦ yyy           ¦ zzz           ¦ aaa           ¦
¦       E002 ¦ aaa           ¦ ccc           ¦ kkk           ¦ jjj           ¦ fff           ¦ ppp           ¦
+-------------------------------------------------------------------------------------------------------------

I came to know about MERGE statement but not sure if it will work.
I am new to oracle pl/sql.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:57:28+00:00Added an answer on June 17, 2026 at 6:57 am
    CREATE TABLE tmp 
      ( 
         row_id NUMBER, 
         id     NUMBER, 
         t1     VARCHAR2(5), 
         t2     VARCHAR2(5), 
         t3     VARCHAR2(5) 
      ); 
    
    INSERT INTO tmp 
    VALUES      (1, 
                 1, 
                 'a', 
                 NULL, 
                 'a'); 
    
    INSERT INTO tmp 
    VALUES      (2, 
                 1, 
                 NULL, 
                 'b', 
                 'b'); 
    
    INSERT INTO tmp 
    VALUES      (3, 
                 1, 
                 'c', 
                 NULL, 
                 NULL); 
    
    INSERT INTO tmp 
    VALUES      (1, 
                 2, 
                 'a', 
                 'a', 
                 NULL); 
    
    INSERT INTO tmp 
    VALUES      (2, 
                 2, 
                 NULL, 
                 'b', 
                 NULL); 
    

    So, we should get: 1,C,B,B and 2,A,B,NULL:

    select id_merged, T1,T2,T3 from 
    ( SELECT id id_merged,
     first_value(T1 IGNORE nulls) over (partition BY id ORDER BY row_id DESC) T1,
     first_value(T2 IGNORE nulls) over (partition BY id ORDER BY row_id DESC) T2,
     first_value(T3 IGNORE nulls) over (partition BY id ORDER BY row_id DESC) T3,
     rank () over (partition by id order by row_id) rn
    FROM tmp)
    where rn=1 ORDER BY id_merged;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which has no primary key and I can't add one
I have 2 table one is a Stage table whose schema is exac to
I have one XML request which I need to modify (to XML) and then
I have one drop down list in my page, which contains two options. What
I have the following FluentNHibernate mapping: public AssetMap() { Table(PRASSET); Id(x => x.Id).Column(PRA_RECNUM).GeneratedBy.Sequence(PRA_RECNUM_GEN); ...fields
I have a query to subtract current balance from one table with previous balance
I have a myisam table with a primary key spanning 5 columns. I do
I have below table, and trying to retrieve the data where at-least one column
I have a MySQL query that is copying data from one table to another
I have the table with 1 column and has following data Status a1 i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.