mysql删除问题

下面这句话删除会有问题

DELETE FROM sys_cost_item WHERE cost_item_id IN (SELECT cost_item_id FROM sys_cost_item WHERE cost_item_name='无' AND cost_type_code!='FEE_INSTALL');

mysql执行报错:You can't specify target table <tbl> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。 改成下面的sql就行了:

DELETE FROM sys_cost_item WHERE cost_item_id IN (SELECT a.cost_item_id FROM
(SELECT b.cost_item_id FROM sys_cost_item b WHERE b.cost_item_name='无' AND b.cost_type_code!='FEE_INSTALL') a
);

 

参考:http://blog.csdn.net/priestmoon/article/details/8016121

posted @ 2016-08-24 14:27  黄昏的麦田  阅读(118)  评论(0编辑  收藏  举报