子组外的引用字段(where 子句中的未知列)
Reference field outside the subgroup (Unknown column in where clause)
我试图在子查询中引用 a.pointer,但看起来 mysql 不允许引用子查询外的字段。
UPDATE order_items AS a
SET a.id_parent = (
SELECT id FROM((
select id from order_items as b where (b.pointer = a.pointer) and (b.id_parent = 0))
)x)
WHERE a.id_parent > 9999
在子查询中访问 a.pointer 的最佳方法是什么?
尝试为此使用连接
UPDATE order_items as a
SET a.id_parent = b.id
JOIN(select id from order_items as c where c.id_parent = 0) b ON b.pointer = a.pointer
WHERE a.id_parent > 9999
您似乎想在这里进行自连接;像
UPDATE order_items a
JOIN order_items b ON b.pointer = a.pointer AND b.id_parent = 0
SET a.id_parent = b.id
WHERE a.id_parent > 9999;
UPDATE a
SET a.id_parent = b.id
from order_items a join order_items b
on (a.pointer = b.pointer )
where b.id_parent = 0 and a.id_parent > 9999
您可以像上面那样使用自连接。
谢谢
我试图在子查询中引用 a.pointer,但看起来 mysql 不允许引用子查询外的字段。
UPDATE order_items AS a
SET a.id_parent = (
SELECT id FROM((
select id from order_items as b where (b.pointer = a.pointer) and (b.id_parent = 0))
)x)
WHERE a.id_parent > 9999
在子查询中访问 a.pointer 的最佳方法是什么?
尝试为此使用连接
UPDATE order_items as a
SET a.id_parent = b.id
JOIN(select id from order_items as c where c.id_parent = 0) b ON b.pointer = a.pointer
WHERE a.id_parent > 9999
您似乎想在这里进行自连接;像
UPDATE order_items a
JOIN order_items b ON b.pointer = a.pointer AND b.id_parent = 0
SET a.id_parent = b.id
WHERE a.id_parent > 9999;
UPDATE a
SET a.id_parent = b.id
from order_items a join order_items b
on (a.pointer = b.pointer )
where b.id_parent = 0 and a.id_parent > 9999
您可以像上面那样使用自连接。
谢谢