带两个内部联接的sqlite delete语句

时间:2019-03-18 18:20:50

标签: sql sqlite

我看过以下两个线程:
How delete table inner join with other table in Sqlite?
SQlite delete inner join
但我很确定这个问题不会重复。

所以我写了这个选择语句:

select * from tags
inner join pictures
    on pictures.id = tags.picture_id
inner join albums
    on pictures.album_id = albums.id
where tags.user_id = 1 and pictures.name = "Me and Obama" and albums.name = "Me and VIPs";

现在我需要用它做一个删除语句。
我尝试用“删除”替换“选择*”,但这不是正确的语法。

我将如何去做?这是我到目前为止的内容:

delete from tags
where picture_id in (select id from pictures where name = "Me and Moshe Dayan") and tags.user_id = 1  

但是它缺少专辑的整个内部连接,我不知道如何实现。
任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

我认为您需要在子查询中使用join

delete from tags
where picture_id in (select p.id
                     from pictures p inner join
                          albums a
                          on p.album_id = a.id
                     where p.name = 'Me and Moshe Dayan' and
                           a.name = 'Me and VIPs'
                    ) and
      tags.user_id = 1  ;
相关问题