-1

The simplified version of my question is:

Say I have two tables. T1 contains the columns ID, C1, C2 and C3. Rows in this table represent complete records.

T2 contains the columns ID, C2 and C3. Rows in this table represent incomplete records.

Now, I want to create a view (V1) in which T1's data is replaced with data from T2 based on matching IDs.

  • 1
    Please specify what you mean by "UPDATE" in your case... – eagle275 Nov 6 at 15:18
  • 1
    Please consider reading this advice – mustaccio Nov 6 at 15:50
  • updated => replaced with – James Alesi Nov 6 at 15:54
2

Something like:

SELECT T1.ID, T1.C1
     , COALESCE(T2.C2, T1.C2) AS C2
     , COALESCE(T2.C3, T1.C3) AS C3
FROM T1
LEFT JOIN T2
    ON T1.ID = T2.ID

If there is no matching row in T2, T2.Cn will be null, COALESCE maps this to T1.Cn

  • 2
    Almost .... C1 exists only in T1 ;-) – eagle275 Nov 6 at 15:48
  • Ah, thanks. I'll update – Lennart Nov 6 at 15:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.