2015-12-11 38 views
-1

實施例:我已插入3點相同的值的數據(A,A,A)到數據庫刪除SQL特定行不參照ID

在數據庫

一個

一個

a

我怎樣才能通過引用行號去除第二行的'a'。

+0

關鍵字:** ** ROWID,更[這裏](https://開頭www.sqlite.org/lang_createtable.html#rowid) – pskink

回答

-1

使用slqlite3你的選擇是

"DELETE from example_table where example_column = 'a';" 

然而,這消除了所有的行用「A」在這其中心不是你想要的。你可以做的是搜索所有'a'位。然後獲取第二個ID,然後刪除該ID的位置。

我假設你的問題,你的意思是你不知道的ID,而不是你沒有一個ID列。 (而你也應該這樣做,或者你將數據庫來得很慢,無法使用)

要實現我的解決方案:

// get the id of the second a row. 
Cursor c = db.rawQuery("SELECT id from example_table where example_column = a ;"); 
// iterate and get 2nd row 
if (c.moveToPosition(1)){ // positions start at 0 in programming 
    int id = c.getInt(0); 
    db.exec("DELETE from example_table where id ="+id+";"); 
}