Avatar of patricka_0377
patricka_0377

asked on 

SQL Server T-SQL - Merge table and delete duplicates

I have the following table

TABLE A

ID,FIELD1,FIELD2,FIELD3
1,VALUE1,VALUE2,VALUE3
2,VALUE1,VALUE2,VALUE3
3,VALUE4,VALUE5,VALUE6

TABLE B (where A_ID is related to TABLE A.ID)

ID,A_ID,STATUS_ID
1,1,1
2,2,3

Records ID 1 + 2 in table A are the same record so I would like to updated the table so that it looks like the following:

TABLE A

ID,FIELD1,FIELD2,FIELD3
1,VALUE1,VALUE2,VALUE3
3,VALUE4,VALUE5,VALUE6

TABLE B

ID,A_ID,STATUS_ID
1,1,1
2,1,3

Removing the duplicate row but moving the related row to be related to record ID = 1

How can I do this in T-SQL?
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
BrandonGalderisi

8/22/2022 - Mon