NYCPHP Meetup

NYPHP.org

[nycphp-talk] every other record

Rahmin Pavlovic rahmin at insite-out.com
Fri Mar 17 17:09:09 EST 2006


On 2/1/06 4:33 PM, "Carlos A Hoyos" <cahoyos at us.ibm.com> wrote:

> If some ids have been removed, you can use a subquery to get the row
> number.
> 
> For example, if you have a table "your_table" with primary key
> "your_table_id", this query will list they key and the row # for this
> entry.
> 
> select (select SUM(1) from your_table where your_table_id
> <=tableAlias.your_table_id) as RowNumber,  your_table_id from your_table_id
> tableAlias;
> 
> add a "having mod(RowNumber,2) =0" to list every other row.
> 

To anyone who was following:

I ran with this solution in development and found it to be smooth (and in
compliance with my 'SQL-side' laurels).

However, once I imported some 100k+ records (all containing large HTML
blobs), the memory on the SQL server would max out.  I did add a join to the
query (300+ records), but that was fine during initial development -- I
found that sum(1) would exponentially tax the memory allocated to MySQL.

Ended up storing results in a multi-dimensional array and looping through
that.





More information about the talk mailing list