W
W
WhatIsHTML2018-04-18 12:21:28
PostgreSQL
WhatIsHTML, 2018-04-18 12:21:28

Merging two tables into one postrgesql?

Conventionally, there are two tables:

create table target
(
  "id" serial primary key,
  "title" varchar(50) not null,
  "poster" varchar(100) default null
);

create table source
(
  "id" serial primary key,
  "posterId" serial REFERENCES target (id)
  "poster" varchar(100) default null
);

I need to copy source.poster to target.poster, according to the condition where source.posterId = target.id
I do this, the result is null
INSERT INTO target ("poster")
SELECT "poster"
FROM source
WHERE source."posterId" = target.id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WhatIsHTML, 2018-04-18
@WhatIsHTML

Programmed in HTML, thanks for the tip to a friend who ran away somewhere

UPDATE target AS t
SET poster = s.poster 
FROM source AS s
WHERE s."posterId" = t.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question