简体   繁体   English

如何在另一个表中的一个表中设置列数据Amazon Redshift

[英]how to set column data in one table from another table Amazon Redshift

I have this usecase where I have a table 'a', which has the same columns as table 'b'. 我有一个用例,其中有一个表“ a”,该表与表“ b”具有相同的列。 What I want is: for all rows that are both in 'a' and 'b', I want 'a' to have the same value for column 'x' as 'b'. 我想要的是:对于同时在“ a”和“ b”中的所有行,我希望“ a”的列“ x”的值与“ b”相同。

Here is what I'm trying but I keep getting stuck: 这是我正在尝试的方法,但我一直陷于困境:

UPDATE a 
   SET a.x = b.x 
   FROM b  INNER JOIN  a  ON a.id = b.id;

Im getting errors: 我收到错误消息:

[Amazon](500310) Invalid operation: table name "a" specified more than once;

Any help would be greatly appreciated! 任何帮助将不胜感激!

You are almost there just use below query 您几乎就在那里使用下面的查询

   UPDATE a 
   SET x = b.x 
   FROM b 
   where 
   a.id = b.id;
UPDATE a
   SET x = b.x
   FROM b
   where a.id = b.id;

This ended up working for me 最终为我工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM