23 February 2015

How To Update Only The First Row Of The Table With Duplicate Column Value

For instance, you have a multiple rows with 3 columns (myName, myAge, myExpertise) like

Harold    34    C#
Harold    12    ASP.NET
Harold    21    LINQ

Now if you just want to update the 2nd column (myAge) of the first row, one solution that should work is the following:

UPDATE myTableName SET myAge=35 WHERE myPrimaryId=(SELECT MIN(myPrimaryId) FROM  myTableName WHERE myName='Harold')

No comments:

Post a Comment