简体   繁体   中英

How to update only last record of SQLite database in android?

I am using SQLite database in android. I need to update the record based on some condition. But there are multiple records that fulfills the condition, so all records are getting updated. I need to update only last one. Please help me.

Thanks in advance

Here is my code

 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[]{});


        }

如果其他人会发现该问题,则可能的答案是:

update table1 set last_accessed_dt = datetime('now') where _id = (SELECT MAX(_id) FROM table1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM