NYCPHP Meetup

NYPHP.org

[nycphp-talk] every other record

Craig Thomas craig at juxtadigital.com
Wed Feb 1 16:08:55 EST 2006


Rahmin Pavlovic wrote:
> On 2/1/06 3:19 PM, "Chris Merlo" <chris at theyellowbox.com> wrote:
> 
> 
>>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...
> 
> 
> Is that not still every other record?  (I don't particularly need every even
> or odd record id, just every other entry.)


Neither one of those *really* selects every other record...they select 
even or odds IDs.  Subtle difference, but a significant difference.

In response to some others: just because ID 4 is missing [for example] 
doesn't mean ID 5 will have a remainder of 0 when divided by 2...he'll 
still get only even IDs with this:

select * from table where mod(id,2)=0

And odd IDs with this:

select * from table where mod(id,2)=1


-- 
Craig




More information about the talk mailing list