postgres query to insert data in a table from other table using combination of two common entries of thecolumns in both tables [closed]

dba.stackexchange https://dba.stackexchange.com/questions/228051

  •  21-01-2021
  •  | 
  •  

Question

I have 2 tables t1 & t2 both containing 3 columns a,b,c the entries in column 'a' and 'b' are same but ordered differently in t1 & t2. I want to use combination of 'a'&'b' entries of t1, and whichever combination matches with t2 enter the respective data in column 'c' of t1 for that combination to t2.

I want it to do on whole column/table in postgres...can anyone help me. Thanks in advance.

Was it helpful?

Solution

UPDATE t2
SET t2.c = t1.c
FROM t1
WHERE t1.a = t2.a
  AND t1.b = t2.b
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top