NYCPHP Meetup

NYPHP.org

[nycphp-talk] every other record

Carlos A Hoyos cahoyos at us.ibm.com
Wed Feb 1 16:33:58 EST 2006


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.

Carlos





More information about the talk mailing list