Delete row in database table given one column value - which is a string

前端 未结 4 785
旧时难觅i
旧时难觅i 2020-12-03 11:09

I have a table with column headings: | _id (long) | Name (String) | x (integer) | y (integer) |

I want to delete the row in the table that has Name myName.



        
4条回答
  •  北海茫月
    2020-12-03 11:31

    depending on the complexity of your where condition, the "delete" method will not be the best solution.

    for example, if you want to delete all records whose "_id" is in a second table, like you would write in transactSQL: "...WHERE _id IN (SELECT _id FROM..." then the best solution might be to use the ".execSQL()" method directly on your database.

    myDatabase.execSQL("DELETE FROM myTable WHERE _id IN (SELECT _id FROM myOtherTable)");
    

    or you could go real ugly and do something like:

    int cursorRows = cursor.getCount();
    String[] id2String = new String[cursorRows];
    String id2StringUnique = "";
    //for (int i=0;i

    depending on number of items, you might have a problem with the length / size of your argument - besides it being diselegant to the extreme.

提交回复
热议问题