mysql - MySQL删除和内部连接问题
问题描述
我需要创建一个查询来删除cfc_registration
具有旧cfc_tournament
.
我的查询:
delete from cfc_registration
inner join cfc_tournament on cfc_tournament.id = cfc_registration.cfcTournamendId
where cfc_registration.cfcTournamentId = cfc_tournament.id and cfc_tournament.createdAt >= DATE_SUB(NOW(),INTERVAL 1 YEAR);
问题 :
#1064 - 'inner join cfc_tournament on cfc_tournament.id = cfc_registration.cfcTournamendI' à la line 2
解决方案
问题在于你DELETE FROM
的开始。您应该使用DELETE t1 FROM table t1
,因为您正在指定要删除的内容。这是在 MySQL 中以这种方式实现的,因为您可以同时从两个表中删除记录。
我相信这应该有效:
DELETE t1
FROM cfc_registration t1
INNER JOIN cfc_tournament t2
ON t2.id = t1.cfctournamendid
WHERE
t1.cfctournamentid = t2.id
AND t2.createdat >= date_sub( now(), interval 1 YEAR );