List:General Discussion« Previous MessageNext Message »
From:JamesD Date:December 22 2002 5:59am
Subject:RE: Return every Nth row in a result set
View as plain text  
seems like it would be easier to 
write a perl script

#repeated SQL selects 
$count=0;
$sth = $dbh->prepare(qq(select * from table LIMIT ?,?)); 
while ($sth){
$sth->execute($count,1);
$ref =$sth->fetchrow_arrayref();
print FILEHANDLE "my item is $ref->[0],$ref->[1]...etc\n";
$count+=5;
}

#or use modulo 

$count=0;
$sth = $dbh->prepare(qq(select * from table)); 
$sth->execute();
$ref =$sth->fetchrow_arrayref();

@stuff = @$ref;		#dereference the array
$total = @stuff;		#get item count

LINE: while ($total) {
next LINE unless ($count == 0||$count % 5 == 0){
print FILEHANDLE "my item is $ref->[0],$ref->[1]...etc\n";
} continue { $count++; $total--;}

Jim
-----Original Message-----
From: SpamSucks86 [mailto:spamsucks86@stripped]
Sent: Saturday, December 21, 2002 8:38 PM
To: mysql@stripped
Subject: Return every Nth row in a result set


What would be the SQL query to return every Nth row in a result set? So
it would return the 5th row, the 10th row, the 15th row, etc. Thanks for
any and all replies!


Thread
Return every Nth row in a result setSpamSucks8622 Dec
  • RE: Return every Nth row in a result setJamesD22 Dec
  • 4.1 questions: subqueries which use dualric22 Dec
    • re: 4.1 questions: subqueries which use dualVictoria Reznichenko24 Dec
  • Re: Return every Nth row in a result setric22 Dec
    • RE: Return every Nth row in a result setSpamSucks8622 Dec
      • Re: Return every Nth row in a result setBenjamin Pflugmann22 Dec
        • RE: Return every Nth row in a result setSpamSucks8622 Dec
          • Re: Return every Nth row in a result setRichard Clarke22 Dec
          • Re: Return every Nth row in a result setric22 Dec
  • Re: 4.1 questions: subqueries which use dualRichard Clarke24 Dec
    • Re: 4.1 questions: subqueries which use dualDan Nelson24 Dec
  • Re: 4.1 questions: subqueries which use dualRichard Clarke24 Dec
    • Re: 4.1 questions: subqueries which use dualMark Matthews24 Dec