Search code examples
sqldb2sql-updatedb2-luw

Update only 1 record in DB2 from multiple identical records?


I'm trying to update a single record which is the exact copy of another record. Is there any way to limit or select only 1 record while updating?

Thanks


Solution

  • You can use FETCH FIRST n ROWS clause .

    UPDATE 
    ( SELECT colA  FROM tableName t WHERE <where condition> FETCH FIRST 1 ROW ONLY
    ) 
    SET t.colA= 'newvalue';