Re: Selecting every 50th row

From: Date: Wed, 03 Dec 2003 06:43:53 +0000
Subject: Re: Selecting every 50th row
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31864@lists.php.net to get a copy of this message
In article <9059269546.20031203054310@launchcode.co.uk>, rich@launchcode.co.uk 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?

« previous php.db (#31864) next »