有人可以解释一下为什么会这样吗?
=> select client_id from clients_to_delete;
ERROR: column "client_id" does not exist at character 8
但是,当把它放在IN()...
中时=> select * from orders where client_id in(select client_id from clients_to_delete);
它有效!并选择orders表中的所有行。运行删除/更新时相同。 为什么它不像以前那样产生错误?
谢谢!
答案 0 :(得分:4)
在此查询中
SELECT *
FROM orders
WHERE client_id IN
(
SELECT client_id
FROM clients_to_delete
)
client_id
取自外部表(orders
),因为内部表(clients_to_delete
)中没有具有此类名称的字段:
SELECT *
FROM orders
WHERE orders.client_id IN
(
SELECT orders.client_id
FROM clients_to_delete
)