0

I'm trying to delete records from db1, that exists in db2. here are my queries:

db.execSQL("attach database '" + db_path + "' as db2");
db.execSQL("DELETE CategoryProduct_MM FROM CategoryProduct_MM INNER JOIN db2.CategoryProduct_MM t2 ON CategoryProduct_MM.PrdID = t2.PrdID AND CategoryProduct_MM.CategoryID=t2.CategoryID");

I'm getting this error:

--------- beginning of crash
    05-31 20:59:54.242 30323-30323/me.superup.updatedb E/AndroidRuntime: FATAL EXCEPTION: main
     Process: me.superup.updatedb, PID: 30323
     android.database.sqlite.SQLiteException: near "CategoryProduct_MM": syntax error (code 1): , while compiling: DELETE CategoryProduct_MM FROM CategoryProduct_MM INNER JOIN superup.CategoryProduct_MM t2 ON CategoryProduct_MM.PrdID = t2.PrdID AND CategoryProduct_MM.CategoryID=t2.CategoryID
         at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
         at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
         at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
         at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
         at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
         at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
         at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
         at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)

what am I doing wrong?

Mauker
  • 11,237
  • 7
  • 58
  • 76
Andrey Rankov
  • 1,964
  • 2
  • 17
  • 33
  • that's not how DELETE works : https://www.sqlite.org/lang_delete.html (I don't think you can do an INNER JOIN either) – njzk2 May 31 '16 at 19:36
  • Actually, you can. http://stackoverflow.com/questions/8364329/sqlite-delete-rows-with-inner-join – Mauker May 31 '16 at 19:39

0 Answers0