我有這樣的數據結構:UPDATE抱怨不止一個返回值
request
=======
building_id
lot_code
building
========
building_id
lot_id
lot
===
lot_id
lot_code
的request
表缺少的building_id
列的值,我想從另一個表中填充它。所以,我已經試過這樣:
UPDATE request
SET building_id = (
SELECT bu.building_id
FROM building bu
INNER JOIN lot lo ON bu.lot_id=lo.lot_id
WHERE lo.lot_code = request.lot_code
);
但我發現了這個錯誤:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
它是由於錯誤的語法?數據模型允許每個建築物有多個建築物,但實際數據不包含這種情況,因此每個lot_code
最多應該有一個building_id
。
該查詢並運行,結果看起來是正確的。謝謝! – 2010-05-13 09:56:54
您好!如果問題解決了,您可以將答案標記爲接受 – Oleg 2010-05-13 10:14:59
+1,這將一次處理多行的UPDATE。 – 2010-05-13 12:16:37