[nycphp-talk] every other record

Dan Cech dcech at
Wed Feb 1 15:33:40 EST 2006

Chris Merlo wrote:
> On 2/1/06, Rahmin Pavlovic <rahmin at> wrote:
>> To the more knowledgeable SQL heads in the house:
>> Do you think it's reliable to mod() the record id to pull every other
>> record, like:
>> select * from table where mod(id,2)=0 #or
>> select * from table where mod(id,2)=1
> Off the top of my head, I can think of a scenario where this will not work.
> If you have a table with an auto-generated ID, where you have ever deleted a
> record, in my experience with MySQL, the deleted ID won't get reused, and so
> your ID values will be 1, 2, 3, 5, 6, 7, etc...  Therefore, that first line
> will grab records with IDs 1, 3, 6, 8, etc...  I would probably write
> something in PHP to grab *all* the records, and then play with every other
> one.

I was thinking the same thing, pulling the entire result and dicarding 
every other row will probably be a lot faster than pulling every other 
row individually.

If you're using the native mysql functions you may be able to traverse 
the record set using mysql_data_seek function to make it a little more 


More information about the talk mailing list