How to UPDATE in SQLite using a LEFT JOIN to select candidate rows

后端 未结 3 441
独厮守ぢ
独厮守ぢ 2020-12-22 10:14

I have a table assoc containing columns

local_id, remote_id, cachedData

I can successfully run an SQLITE query that looks like

相关标签:
3条回答
  • 2020-12-22 10:53

    If assoc has a single column as the primary key (and assuming that it is local_id):

    UPDATE assoc
    SET cachedData=NULL
    WHERE local_id IN (
      SELECT local_id FROM assoc a1 LEFT JOIN ...
    );
    
    0 讨论(0)
  • 2020-12-22 10:58
     UPDATE assoc SET cachedData = NULL
        WHERE EXISTS (SELECT * FROM otherTable 
            WHERE otherTable.Col1 = assoc.Col1 AND otherTable.Col2 = assoc.Col1)
    

    Be aware that this is not especially performant.

    0 讨论(0)
  • 2020-12-22 11:06

    Aha, there's already a builtin rowid!

    UPDATE assoc
    SET cachedData=NULL
    WHERE rowid IN (
       SELECT rowid FROM assoc a1 LEFT JOIN ...
    );
    
    0 讨论(0)
提交回复
热议问题