UPDATE statement in Oracle using SQL or PL/SQL to update first duplicate row ONLY UPDATE statement in Oracle using SQL or PL/SQL to update first duplicate row ONLY oracle oracle

UPDATE statement in Oracle using SQL or PL/SQL to update first duplicate row ONLY


Will this work for you:

update duptest set nonid = 'c'WHERE ROWID IN (SELECT   MIN (ROWID)                              FROM duptest                           GROUP BY id, nonid)


This worked for me, even for repeated runs.

--third, update the one rowUPDATE DUPTEST DTSET DT.NONID = 'c'WHERE (DT.ID,DT.ROWID) IN(                         --second, find the row id of the first dup                         SELECT                            DT.ID                          ,MIN(DT.ROWID) AS FIRST_ROW_ID                         FROM DUPTEST DT                         WHERE ID IN(                                    --first, find the dups                                    SELECT ID                                    FROM DUPTEST                                    GROUP BY ID                                    HAVING COUNT(*) > 1                                    )                         GROUP BY                           DT.ID                         )


I think this should work.

UPDATE DUPTEST SET NONID = 'C'WHERE ROWID in (    Select ROWID from (        SELECT ROWID, Row_Number() over (Partition By ID, NONID order by ID) rn    ) WHERE rn = 1)