Ben’s Digital

Icon

Runner Never Stop

SQL Update Value of column/row from another row

If you have one table and you want to update the value of the current row with the values from another row(NOT the column of the current row)

e.g. column LN, FN, MI of the current rows that you want to update from another rows in the table (replace the tableName of your table, keyColumn of the key that you want to match and t1 and t2 conditions

--UPDATE VALUE FROM ONE ROW TO ANOTHER ROW
UPDATE t1
SET
SUB_LN = t2.SUB_LN
,SUB_FN = t2.SUB_FN
,SUB_MI = t2.SUB_MI
FROM tableName AS t1
INNER JOIN
tableName AS t2
ON t1.keyColumn = t2.keyColumn
WHERE t1.updateCondintion = 'U'
AND t2.valueCondition ='V'

Filed under: Database, SQL

Leave a Reply

You must be logged in to post a comment.

Flickr

  • Bensdigital Flickr

Twitter

  • Bensdigital Twitter