2013-08-05 53 views
0

以下是返回語法錯誤問題。 在網上徹底搜索後,我看不出爲什麼。有任何想法嗎?SQL從連接表中刪除不起作用

delete Tracks                                      
from tracks                                          
left join releases                                        
on tracks.label_id=releases.label_id                                    
where tracks.label_id = 185 
and releases.id = 4394 
and tracks.position = 1 
and tracks.name != 'Da Antidote'; 

語法錯誤是1號線。

+0

錯誤說的是什麼?你能顯示整個錯誤信息嗎? –

+0

可能是一個大小寫敏感的問題。你有沒有試過'從軌道刪除曲目 ...'? –

回答

2

如果我沒有記錯的Postgres不允許加入在DELETE,但你可以使用關鍵字USING,而不是像described in the documentation

DELETE FROM Tracks 
USING releases 
WHERE tracks.label_id=releases.label_id 
AND tracks.label_id = 185 
AND releases.id = 4394 
AND tracks.position = 1 
AND tracks.name != 'Da Antidote'; 
+0

完美!謝謝jpw。在將來詢問之前,我一定會查閱文件。再次感謝 – edhamilton812

1
delete from tracks                                          
left join releases                                        
on tracks.label_id=releases.label_id                                    
where tracks.label_id = 185 
and releases.id = 4394 
and tracks.position = 1 
and tracks.name != 'Da Antidote'; 
+0

這不起作用,因爲您不能在Postgres中使用連接刪除。 – jpw

0

您可以使用EXISTS子句:

DELETE FROM tracks t1 WHERE EXISTS (
    SELECT 1 FROM releases t2 WHERE 
     t1.label_id = t2.label_id 
     AND yadda, yadda, yadda 
);