子查询应该总是 select 语句吗?
Should Subqueries always be select statements?
select * from product where customer_id = (delete from product where product_id = 5 and customer_id = 1 returning customer_id);
当我 运行 上面的查询时,我得到:
错误:“from”处或附近的语法错误
但是 运行ning delete from product where product_id = 5 and customer_id = 1 returning customer_id
单独工作正常并返回 customer_id。
所以问题是子查询是否总是 select 语句?
有没有其他方法可以在一个查询中删除和 select?
使用 CTE:
with d as (
delete from product
where product_id = 5 and customer_id = 1
returning customer_id
)
select p.*
from product p
where p.customer_id in (select d.customer_id from d);
select * from product where customer_id = (delete from product where product_id = 5 and customer_id = 1 returning customer_id);
当我 运行 上面的查询时,我得到:
错误:“from”处或附近的语法错误
但是 运行ning delete from product where product_id = 5 and customer_id = 1 returning customer_id
单独工作正常并返回 customer_id。
所以问题是子查询是否总是 select 语句? 有没有其他方法可以在一个查询中删除和 select?
使用 CTE:
with d as (
delete from product
where product_id = 5 and customer_id = 1
returning customer_id
)
select p.*
from product p
where p.customer_id in (select d.customer_id from d);