P
P
P7472021-12-22 20:28:37
PostgreSQL
P747, 2021-12-22 20:28:37

PostgreSQL, condition on column from INSERT?

Good afternoon!
I will lay out at once an example of a code which does not work. How to make it possible to add a condition on a column from the INSERT table to WHERE?

INSERT INTO table1 (
    column1
)
SELECT column2
FROM table2
WHERE (column2 = table1.column3)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-12-22
@P747

JOIN ordinary or IN/EXISTS

INSERT INTO table1 (
    column1
)
SELECT column2
FROM table2
WHERE column2 IN (SELECT table1.column3 FROM table1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question