0

下面返回一个语法错误问题。在网上彻底搜索后,我不明白为什么。有任何想法吗?

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 行。

4

3 回答 3

2

如果我没记错的话,Postgres 不允许加入DELETE,但您可以使用该USING关键字,如文档中所述

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';
于 2013-08-05T09:23:06.623 回答
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';
于 2013-08-05T09:19:36.387 回答
0

您可以使用 EXISTS 子句:

DELETE FROM tracks t1 WHERE EXISTS (
    SELECT 1 FROM releases t2 WHERE 
        t1.label_id = t2.label_id
        AND yadda, yadda, yadda
);
于 2013-08-05T21:20:50.270 回答