2014-10-09 58 views
0

刪除執行此查詢後:與加盟錯誤

DELETE from swimming_class as tb1 JOIN (SELECT class_id FROM `swimming_class` 
left join swimming_school on swimming_school.school_id = swimming_class.school_id 
where swimming_school.school_name is NULL) as temp ON temp.class_id = tb1.class_id 

我得到這個錯誤:

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 tb1 JOIN (SELECT class_id FROM swimming_class left join swimming_school on' at line 1

+0

您無法從JOIN中正在使用的任何表中刪除,並且在DELETE語句中刪除表的別名 – Sal00m 2014-10-09 13:53:05

+0

@ Sal00m那麼,你可以 - 你只需要有點聰明;-) – Strawberry 2014-10-09 13:56:40

回答

0

我想你是真的什麼是後以下(SQL Fiddle):

DELETE sc 
FROM swimming_class sc 
INNER JOIN swimming_school ss ON ss.school_id = sc.school_id 
WHERE ss.school_name is NULL 
+0

#1093 - 你不能指定目標表'swimming_class'在FROM子句 – Shin 2014-10-09 13:50:46

+0

** @ Shijin **更新,我更新了我的答案,幷包括一個示範。那是你的追求? – Linger 2014-10-09 14:05:11

+0

@使用'LEFT JOIN',查看原始查詢 – Rimas 2014-10-09 14:06:49