Delete first N rows in android sqlite database

后端 未结 7 1948
北恋
北恋 2020-12-14 09:37

Please let me know how to delete n-rows in android sqlite database. I used this code:

   String ALTER_TBL =\"delete from \" + MYDATABASE_TABLE +
         \"w         


        
7条回答
  •  感动是毒
    2020-12-14 10:34

    You can make use of the following mode: (in addition to the response provided by "zapl").

    **DELETE FROM {Table-X} WHERE _ID NOT IN 
     (SELECT _ID FROM {Table-X} ORDER BY _ID DESC/ASC LIMIT (SELECT {Limit-Column} FROM {SpecificationTable})  );**
    

    Where {Table-X} refers to the table you want to delete, _ID is the main unique-column DESC/ASC - Based on whether you want to delete the top records or the last records, and finally in the "LIMIT" clause, we provide the "n" factor using another query, which calls in the {Limit-Column} from {SpecificationTable}: Which holds the value against which you want to delete them.

    Hope this helps out someone.

    Happy Coding.

提交回复
热议问题