PSQL join - 列“table.column”不存在

时间:2018-03-23 09:22:10

标签: sql postgresql sql-update inner-join

我需要更新表中的记录,但前提是此表的某个列等于另一个表的列的内容。

但首先,为了确保,我想选择满足这一特定条件的所有记录,所以我尝试过类似的事情:

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

但查询返回此错误:

  

错误:列“AOP.col2”不存在   第1行:......作为ARR INNER JOIN“table2”作为AOP ON(“AOP.col ...

我做错了什么? (显然该栏确实存在)
看到此错误,您认为以下更新查询也会失败吗?

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

2 个答案:

答案 0 :(得分:0)

SELECT * FROM table1 ARR INNER JOIN table2 AOP ON AOP.col2 = ARR.col1

答案 1 :(得分:0)

[解决]

如果有人对解决方案感兴趣,那就是:

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