从MySQL中的select中删除

时间:2017-02-03 19:33:40

标签: mysql sql

我试图从以下SELECT查询中删除结果行

select customer_ID, order_ID, t1, t2 
from web_order, items_table as a, items_table as b
  where (web_order.t1 = a.item_name and a.quantity) 
   and (web_order.t2 =  b.item_name and b.quantity)
   and ((a.quantity < b.quantity));

这是我的DELETE查询

delete from web_order where customer_ID in
(select customer_ID, order_ID, t1, t2 
 from web_order, items_table as a, items_table as b
   where (web_order.t1 = a.item_name and a.quantity) 
     and (web_order.t2 = b.item_name and b.quantity)
     and ((a.quantity < b.quantity)));

但我收到此错误

ERROR 1241 (21000): Operand should contain 1 column(s)

1 个答案:

答案 0 :(得分:2)

您无法从删除语句中删除的表中进行选择 - 这就像在迭代时尝试添加/删除集合中的项目一样。

以下是MySQL docs的正式声明:

  

<强>子查询

     

您无法从表中删除并从中选择同一个表   子查询。

您需要使用select语句将customer_ID值插入临时表,然后从删除中的临时表中进行选择。

所以,它看起来像这样(我假设Customer_ID是你的web_order表中的INT列):

functionOne called
Returning promise.
functionTwo called (should be called after Done is finished.)
Starting Done.
Done finished.