【问题标题】:sqlite delete statement with two inner joins带有两个内部连接的 sqlite 删除语句
【发布时间】:2019-03-18 18:20:50
【问题描述】:

我看过这两个帖子:
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”替换“select *”,但这不是正确的语法。

我该怎么做呢?这是我目前所拥有的:

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

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

【问题讨论】:

  • 旁注:SQL 使用双引号来标记表和列名等标识符,并使用单引号标记字符串。如果没有与内容匹配的标识符,Sqlite 有时会将双引号视为字符串,但最好还是坚持标准并使用单引号:'Me and Obama' 等。

标签: sql sqlite


【解决方案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  ;

【讨论】:

    猜你喜欢
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多