我在android中使用SQLite数据库。我需要根据某些条件更新记录。但是有多个记录符合条件,因此所有记录都会更新。我只需要更新最后一个。请帮帮我。
提前致谢
这是我的代码
public void UPDATE_INVOICE(int invoice_id,int owner_id,int vehicle_id,String invoice_date,String invoice_time,String dest,String distance,String validity_date, int qty,String local_var)
{
SQLiteDatabase db=getWritableDatabase();
ContentValues values = new ContentValues();
values.put(INVOICE_NUMBER, invoice_id);
values.put(INVOICE_DATE, invoice_date);
values.put(INVOICE_TIME, invoice_time);
values.put(INVOICE_VALIDITY_DATE, validity_date);
values.put(INVOICE_QTY, qty);
values.put(INVOICE_LOCAL, local_var);
db.update(TABLE_INVOICE_DETAILS, values, INVOICE_OWNER_ID_REF+"="+owner_id+" and "+INVOICE_VEHICLE_ID_REF+"="+vehicle_id, new String[]{});
}
答案 0 :(得分:0)
如果其他人会发现这个问题,那么可能的答案是:
update table1 set last_accessed_dt = datetime('now') where _id = (SELECT MAX(_id) FROM table1);