[android-developers] Re: Is there sqlite statement to delete first 5 rows?

2012-07-01 Thread Mystique
Ok, make sense. Understood now.
Thanks.

On Sunday, 1 July 2012 22:56:22 UTC+8, RichardC wrote:
>
> SQL statements are set based.  By this I mean that unless you order the 
> data in the query SQL does not have to return the data in the same order 
> each time to make the same call.
>
> If I assume that you have an ID column which you can order on the the 
> following will work (when you remove any typos I make):
>
> DELETE FROM my-table WHERE my-table.id IN (SELECT id FROM my-table ORDER 
> BY id LIMIT 5)
>
>
> On Sunday, July 1, 2012 3:44:23 PM UTC+1, Mystique wrote:
>>
>> Hi, let's say I want to delete top 5 rolls of data from the table.
>> I can do a while loop with an counter call "i" and use 
>> "cursor.moveToPosition(i)" to move to the row and delete it.
>>
>> Is there a better way to do that?
>>
>> Thanks.
>>
>>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Is there sqlite statement to delete first 5 rows?

2012-07-01 Thread RichardC
SQL statements are set based.  By this I mean that unless you order the 
data in the query SQL does not have to return the data in the same order 
each time to make the same call.

If I assume that you have an ID column which you can order on the the 
following will work (when you remove any typos I make):

DELETE FROM my-table WHERE my-table.id IN (SELECT id FROM my-table ORDER BY 
id LIMIT 5)


On Sunday, July 1, 2012 3:44:23 PM UTC+1, Mystique wrote:
>
> Hi, let's say I want to delete top 5 rolls of data from the table.
> I can do a while loop with an counter call "i" and use 
> "cursor.moveToPosition(i)" to move to the row and delete it.
>
> Is there a better way to do that?
>
> Thanks.
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Is there sqlite statement to delete first 5 rows?

2012-07-01 Thread Nobu Games
Usually you would write something like

DELETE FROM MyTable WHERE XYZ ORDER BY Col *LIMIT 5*;

Unfortunately SQLite does not support the LIMIT clause in DELETE 
statements. 
But I think you could get around with something else:

DELETE FROM MyTable WHERE _id IN (SELECT _id FROM MyTable WHERE XYZ ORDER 
BY Col LIMIT 5);

I did not try that, though...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en