我需要从一个表中获取数据以添加到另一个表中。
我有两条 SQL:
SQL1:
select * from table1;
SQL2:
select * from table2 where coloumn1 = table1.coloumn6 (number)
表1看起来像:
为了更好地理解,我们将每个列称为coloumn1、coloumn2、...coloumn9
表2看起来像:
为了更好地理解,我们将每个列称为coloumn1、coloumn2、...coloumn13
文本中应该发生什么
My SQL 必须从 table1.coloumn6
(数字)获取值 - 检查 table2.coloumn1
中是否给出了该值
select * from table2 where coloumn1 = table1.coloumn6 (SQL2)
如果是,则应将数据从 table1.coloumn2
(varchar2) 更新为 table2.coloumn4
(varchar2)。
最佳答案
如果我理解正确的话,您希望根据其他条件将table1.column2
更新为table2.column1
中的相应值。根据您的描述:
update table1
column2 = (select column4 from table2 t2 where t2.column1 = table1.column6)
where exists (select 1 from table2 t2 where t2.column1 = table1.column6);
关于sql oracle 使用更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30079831/