-1

I have employee table where it keep the history with Active data indicator , recently we have provided new Emp ID and the emp table got updated with active data indicator Y for all new employee ID update , where as old emp id got 'N'

Now i wanted to update the old emp id with new emp id , i have around 10K records with this scenrio , so is there any way that i can update all old emp id with new id ? is there any way i can update them ? i wanted to update only emp id column

data there:

Name UNQ ID EMP ID Update date Active Data
Sam D q1212 12356 04/11/2022 Y
Sam D q1212 00123 03/13/2020 N
Sam D q1212 00123 12/12/2019 N

data i wanted to have:

Name UNQ ID EMP ID Update date Active Data
Sam D q1212 12356 04/11/2022 Y
Sam D q1212 12356 03/13/2020 N
Sam D q1212 12356 12/12/2019 N

Since i am new to oracle , i have no idea how to do that

MT0
  • 143,790
  • 11
  • 59
  • 117
  • Duplicate of https://stackoverflow.com/questions/76557580/oracle-bulk-update-with-same-column – MT0 Jun 26 '23 at 15:06

1 Answers1

-1

Assuming unq_id uniquely identifies your employee, a simple update should suffice by getting the emp_id for the same unq_id where the flag is Y:

UPDATE employee e1
   SET emp_id = (SELECT MAX(e2.emp_id)
                   FROM employee e2
                  WHERE e2.unq_id = e1.unq_id
                    AND e2.active_data = 'Y')
 WHERE active_data = 'N'
Paul W
  • 5,507
  • 2
  • 2
  • 13