用另一个表中的值更新表 [英] Update table with value from another table

查看:97
本文介绍了用另一个表中的值更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过使用IP_ID通过遵循sybtax来比较2个表的方式来更新一个表中的值

I try to update value from one table with another table by use IP_ID to compare 2 table by following sybtax

UPDATE EDWID02.CUSTOMER_MOBILE t1
   SET T1.MOBILE = (
      SELECT T2.MOBILE
      FROM EDWID02.NEW_MOBILE t2
      WHERE T1.IP_ID=T2.IP_ID)

我发现的错误是DB2数据库错误:

The error I found was DB2 Database Error:

ERROR [21000] [IBM][DB2/AIX64] SQL0811N  The result of a scalar fullselect, 
SELECT INTO statement, or VALUES INTO statement is more than one row.  
SQLSTATE=21000

即使我更改=到,它也告诉我另一个错误DB2数据库错误:

even I change = to in it's told me another error DB2 Database Error:

ERROR [42601] [IBM][DB2/AIX64] SQL0104N  An unexpected token "in" was found
following "t1    SET T1.MOBILE".  Expected tokens may include:  "=".
SQLSTATE=42601

我正在DB2中进行编码。

I am coding in DB2.

推荐答案

您的误解

'UPDATE t1 SET value=onevalue'

一个值必须是单个值。您可以通过以下方式实现此目的:(从t2的t1位置选择t1.id = t2.id,仅获取第一行)

onevalue needs to be a single value. You may achieve this by (SELECT value FROM t2 WHERE t1.id = t2.id FETCH FIRST 1 ROW ONLY)

这篇关于用另一个表中的值更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆