Does SQLite support “delete from from”

后端 未结 2 633
心在旅途
心在旅途 2021-01-23 17:56

This is valid syntax on Microsoft SQL Server\'s T-SQL, but not in SQLite, is there an alternative syntax that does the same in SQLite?

DELETE FROM something
FROM         


        
相关标签:
2条回答
  • 2021-01-23 18:15

    Here you have an alternative:

    DELETE FROM slave
    where slave.master_id in (select master.id from master where master.something=1234)
    
    0 讨论(0)
  • 2021-01-23 18:24

    In the general case, move the entire join into a subquery that looks up the primary keys of the rows to be deleted:

    DELETE FROM something
    WHERE id IN (SELECT something.id
                 FROM something
                 JOIN combinations ON something.field1=combinations.field1
                                  AND something.field2=combinations.field2
                 WHERE combinations.something=1234)
    

    If you have a composite primary key, you can use the rowid instead:

    DELETE FROM something
    WHERE rowid IN (SELECT something.rowid
                    FROM something
                    JOIN combinations ON something.field1=combinations.field1
                                     AND something.field2=combinations.field2
                    WHERE combinations.something=1234)
    

    If you have a composite primary key and you created the table as a WITHOUT ROWID table, you have to rewrite the join as a correlated subquery:

    DELETE FROM something
    WHERE EXISTS (SELECT 1
                  FROM combinations
                  WHERE field1 = something.field1
                    AND field2 = something.field2
                    AND field3 = 1234)
    
    0 讨论(0)
提交回复
热议问题