Re: Selecting every 50th row

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <9059269546.20031203054310@xxxxxxxxxxxxxxxx>, 
rich@xxxxxxxxxxxxxxxx says...
> Hi php-db,
> 
> I have a table with approx. 250,000 rows in it. The primary key is an
> ID field. All I am wondering is - is there any way at all from MySQL
> to directly select every 50th row in this table?
> 
> I.e. row 1, 50, 100, 150, etc and return the ID of each row, ideally
> with some kind of limit. Even if it was only possible to select the
> IDs of two rows, i.e. row 1 and row 50, that would be good too.
> 
> It's almost like I need a "step" function, like in a FOR NEXT
> statement, only SQL-side.

For a simplistic solution(?) assuming that your ID is integer and there 
are no gaps in the sequence, you could do a single select where ID mod 50 
is zero.

Cheers
-- 
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux