我正在尝试通过以下 SQL 语句删除一些记录,但出现错误#1064 - 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 'GROUP BY tsa_.task_attachment_id H' at line 12:
有谁知道我该如何解决这个错误?
DELETE
ta
FROM `tasks_recursive` AS tr
INNER JOIN `tasks_attachments` AS tsa ON tsa.task_id = tr.id
INNER JOIN `task_attachments` AS ta ON tsa.task_attachment_id = ta.id AND ta.creator_id = 279
INNER JOIN (
`tasks_attachments` AS tsa_
INNER JOIN `tasks_recursive` AS tr_ ON tr_.id = tsa_.task_id
) ON tsa_.task_attachment_id = tsa.task_attachment_id
WHERE
ta.file_name IN ( '000531994879c3bf.pdf', '000531994879c5a8.pdf' )
GROUP BY
tsa_.task_attachment_id
HAVING
COUNT( DISTINCT( tr_.task_id ) ) = 1
我还尝试了以下句子,出现此错误#1064 - 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 'GROUP BY tsa_.task_attachment_id HAVING COUNT( DISTINCT( tr_.task_id ' at line 12:
删除
ta
FROM `tasks_recursive` AS tr
INNER JOIN `tasks_attachments` AS tsa ON tsa.task_id = tr.id
INNER JOIN `task_attachments` AS ta ON tsa.task_attachment_id = ta.id AND ta.creator_id = 279
内部联接 (
`tasks_attachments` AS tsa_
INNER JOIN `tasks_recursive` AS tr_ ON tr_.id = tsa_.task_id
) ON tsa_.task_attachment_id = tsa.task_attachment_id
在哪里
ta.file_name IN ('000531994879c3bf.pdf', '000531994879c5a8.pdf')
通过...分组
tsa_.task_attachment_id
拥有
计数(DISTINCT(tr_.task_id))=1
上面的句子在将表链接到主表的表中查找task_attachments未被任何人 ecxept 本身使用的行。many_to_many tasks_attachmentsslave task_attachmentstasks_recursive
为了解决workaround上述问题,我尝试wrap了above query但我收到了这个错误#1093 - You can't specify target table 'ta_' for update in FROM clause:
删除ta_
FROM `task_attachments` AS ta_
哪里 ta_.id 在
(
选择
ta.id
FROM `tasks_recursive` AS tr
INNER JOIN `tasks_attachments` AS tsa ON tsa.task_id = tr.id
INNER JOIN `task_attachments` AS ta ON tsa.task_attachment_id = ta.id AND ta.creator_id = 279
内部联接 (
`tasks_attachments` AS tsa_
INNER JOIN `tasks_recursive` AS tr_ ON tr_.id = tsa_.task_id
) ON tsa_.task_attachment_id = tsa.task_attachment_id
在哪里
ta.file_name IN ('000531994879c3bf.pdf', '000531994879c5a8.pdf')
通过...分组
tsa_.task_attachment_id
拥有
计数(DISTINCT(tr_.task_id))=1
)
最后尝试了双包装,但也没有用,这是错误#1064 - 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 'AS sub )' at line 25:
删除
FROM `task_attachments`
WHERE `task_attachments`.id IN
(
选择
ta_.id
FROM `task_attachments` AS ta_
哪里 ta_.id 在
(
选择
ta.id 说完
FROM `tasks_recursive` AS tr
INNER JOIN `tasks_attachments` AS tsa ON tsa.task_id = tr.id
INNER JOIN `task_attachments` AS ta ON tsa.task_attachment_id = ta.id AND ta.creator_id = 279
内部联接 (
`tasks_attachments` AS tsa_
INNER JOIN `tasks_recursive` AS tr_ ON tr_.id = tsa_.task_id
) ON tsa_.task_attachment_id = tsa.task_attachment_id
在哪里
ta.file_name IN ('000531994879c3bf.pdf', '000531994879c5a8.pdf')
通过...分组
tsa_.task_attachment_id
拥有
计数(DISTINCT(tr_.task_id))=1
) 作为子
)