List:General Discussion« Previous MessageNext Message »
From:Scott Haneda Date:May 12 2006 7:03pm
Subject:Re: Returning records in a circle
View as plain text  
> Is there a way I can get a set of records incrementally such as to get 2
> then the next query get the next 2 then at the end of all records to get the
> 2 from the beginning? I need to keep going incrementally by 2 in a circle.

I don't know any way to do this directly with SQL, but I could be wrong,
stored procedures may help you here, I do not use mysql 5, so I have not
played with them yet.

I would probably do this with a second table, and some SQL in the middle of
it all to make it happen.  Your second table would simply store the last id
that you selected.

So, you select from your second table, to get the last id you retrieved.
Them you select from the primary table, where id > retreived_id limit 2,
once you have that, take the ID from the last record in the 2 you just got
back, and insert/update that data into your second table.

Make sure you add in app logic to deal with cases where the second table has
never been inserted into, also when you wrap your record set, it will need
to be reset, but I think you get the idea.
-- 
-------------------------------------------------------------
Scott Haneda                                Tel: 415.898.2602
<http://www.newgeo.com>                     Novato, CA U.S.A.


Thread
Returning records in a circleSteffan A. Cline12 May
  • Re: Returning records in a circleRhino12 May
    • Re: Returning records in a circleSteffan A. Cline12 May
  • Using a stored procedure inside a viewChris Carrier12 May
  • Re: Returning records in a circleScott Haneda12 May
RE: Returning records in a circleGeorge Law12 May
  • Re: Returning records in a circleRhino12 May