Firebird SQL

时间:2015-05-02 10:05:05

标签: mysql firebird

也许有人知道该怎么做。在MySQL中我会这样做:

UPDATE T1
SET T1.c2 = T2.c2
WHERE T1.c1 = T2.c1 

不幸的是,在Firebird中尝试此操作会导致错误并产生以下响应:

SQL Message : -204
Undefined name

Engine Code    : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -204
Table unknown
T1
At line 2, column 1

有人有想法吗?

2 个答案:

答案 0 :(得分:2)

Firebird UPDATE语句只能引用单个表。要做你想做的事,你有两个选择。

使用相关子查询:

UPDATE T1
SET c2 = (SELECT T2.c2 FROM T2 WHERE T2.c1 = T1.c1)

或使用MERGE

MERGE INTO T1
USING T2
ON T1.c1 = T2.c1
WHEN MATCHED THEN
   UPDATE SET T1.c2 = T2.c2

答案 1 :(得分:1)

在访问它们之前,您需要提及这两个表。

尝试:

UPDATE T1, T2
SET T1.c2 = T2.c2
WHERE T1.c1 = T2.c1 

或者

update t1
  inner join t2
    on t1.c1 = t2.c1
  set t1.c2 = t2.c2

修改

显然firebird不支持更新中的联接,所以请尝试:

update t1
  set t1.c2 = (select c2 from t2 where c1 = t1.c1);