How delete table inner join with other table in Sqlite?

后端 未结 2 1889
既然无缘
既然无缘 2020-11-28 13:08

My query:

DELETE a FROM TR_ContactResultRecord  a
INNER JOIN TR_Case  b on (a.FireStationCode=b.FireStationCode and a.CaseNo=b.CaseCode )
WHERE b.Update_Date         


        
相关标签:
2条回答
  • 2020-11-28 13:57

    Try to rewrite you query using subquery: In case your PK for TR_ContactResultRecord is CaseNo

    DELETE FROM TR_ContactResultRecord
    WHERE CaseNo IN (
      SELECT CaseNo FROM TR_ContactResultRecord a
      INNER JOIN TR_Case b
        ON (a.FireStationCode=b.FireStationCode and a.CaseNo=b.CaseCode )
      WHERE b.Update_DateTime <=20140628134416
    );
    
    0 讨论(0)
  • 2020-11-28 14:07

    SQLite has special ROWID column by default in each table. From official documentation:

    You can access the ROWID of an SQLite table using one of the special column names ROWID, _ROWID_, or OID. Except if you declare an ordinary table column to use one of those special names, then the use of that name will refer to the declared column not to the internal ROWID.

    The code is following:

    DELETE FROM TR_ContactResultRecord
    WHERE ROWID IN (
      SELECT a.ROWID FROM TR_ContactResultRecord a
      INNER JOIN TR_Case b
        ON (a.FireStationCode=b.FireStationCode and a.CaseNo=b.CaseCode )
      WHERE b.Update_DateTime <=20140628134416
    );
    
    0 讨论(0)
提交回复
热议问题