修改选择查询以删除查询

时间:2011-02-11 10:31:20

标签: mysql

以下选择查询可以正常工作:

SELECT * FROM JBPM_JOB job WHERE job.ACTION_ IN (SELECT ID_ from JBPM_ACTION WHERE ACTIONEXPRESSION_ LIKE '%#{reminderAction.addAsyncProcessReminder%warning%');

但是,当我尝试删除此处检索到的行时,它会失败

DELETE FROM JBPM_JOB job WHERE job.ACTION_ IN (SELECT ID_ from JBPM_ACTION WHERE ACTIONEXPRESSION_ LIKE '%#{reminderAction.addAsyncProcessReminder%warning%');

这里有什么问题?

错误消息是:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'job WHERE job.ACTION_ IN (SELECT ID_ from JBPM_ACTION WHERE ACTIONEXPRESSION_ LI' at line 1

2 个答案:

答案 0 :(得分:1)

您需要指定从别名表中删除,因此请使用:

DELETE job FROM JBPM_JOB job WHERE job.ACTION_ IN (SELECT ID_ from JBPM_ACTION WHERE ACTIONEXPRESSION_ LIKE '%#{reminderAction.addAsyncProcessReminder%warning%');

答案 1 :(得分:0)

我在sql server中测试了查询。工作正常但有可能你删除的值与PK和FK等其他表有一些关系。

如果有,那么你也必须从那些表中删除记录..........