Gossamer Forum
Home : General : Databases and SQL :

fetchrow_array() remove dupes?

Quote Reply
fetchrow_array() remove dupes?
Following is the code used in my CGI script.

$query = $dbh -> prepare("SELECT * FROM invoices WHERE ID = '$ID'");
$query -> execute();
while (my @row = $query -> fetchrow_array()){
print "$row[1] - $row[2] - $row[3]<br>";

What If I want to remove dupes from @row? like if $row[2] is similar in multiple records, only one entry should be showed, the duplicates should not appear in the print.

I am aware of grep, but unable to implement it here in While loop.

= grep {++$count{$_} < 2} @row;

Any ideas?

Last edited by:

samsara: Mar 23, 2005, 1:00 PM
Quote Reply
Re: [samsara] fetchrow_array() remove dupes? In reply to

You could use DISTINCT() to only fetch distinct rows, or in perl:

while (...) {
next if $seen{$row[key]}++;


Gossamer Threads Inc.