Search code examples
sqlpostgresqlsql-updateinner-join

PSQL join - Column "table.column" does not exist


I need to update records in a table but only if a certain column of this table equals the content of a column of another table.

But first, just to be sure, I want to select all of the records that meets this specific so I've tried something like:

SELECT * FROM "table1" as ARR INNER JOIN "table2" as AOP ON ("AOP.col2" = "ARR.col1");

But the query returns this error:

ERROR: column "AOP.col2" does not exist
LINE 1: ...as ARR INNER JOIN "table2" as AOP ON ("AOP.col...

What am I doing wrong? (obviously the column does exist)
Seeing this error do you think the following update query will also fail?

UPDATE "table2" AS AOP
SET "col2" = "ARR.col1"
FROM "table1" AS ARR
WHERE "AOP.col3" = "ARR.col4";

Solution

  • [SOLVED]

    If anyone's interested in the solution this is it:

    SELECT * FROM "table1" as "ARR" INNER JOIN "table2" as "AOP" ON ("AOP"."col2" = "ARR"."col1");