-1

I have 2 tables in postgres like:

table A:

unique_coords unique_id
a 1
b 2
c 3
d 4
. .

table B like:

coords id
a
a
c
d
c
c
d
c

I want to fill the id column in table B based on table A. So the result will be like this:

coords id
a 1
a 1
c 3
d 4
c 3
c 3
d 4
c 3

1 Answer 1

1

This is a simple UPDATE join syntax

UPDATE tableB
SET id = unique_id
FROM tableA
WHERE tableA.unique_coords = tableB.coords;

https://dbfiddle.uk/?rdbms=postgres_14&fiddle=6f820b75952c90ae7cdeadec419f45f6

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