whittick has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I have a script (below) and rather than cycle through each row of the table I would like to just return the first row. Is this possible?
my $query="SELECT severity, source, displayname FROM alert WHERE displ +ayname LIKE '%$displayname%' ORDER BY severity DESC"; my $sth=$dbh->prepare($query); $sth->execute(); #Loop through for each row returned while ( @row = $sth->fetchrow_array ) { $severity = $row[0]; $source = $row[1]; $displayname = $row[2]; print "$severity\n"; }
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: returning first row of SQL query
by moritz (Cardinal) on Mar 29, 2012 at 12:35 UTC | |
|
Re: returning first row of SQL query
by Anonymous Monk on Mar 29, 2012 at 12:02 UTC | |
by whittick (Acolyte) on Mar 29, 2012 at 12:08 UTC | |
|
Re: returning first row of SQL query
by marto (Cardinal) on Mar 29, 2012 at 12:29 UTC | |
|
Re: returning first row of SQL query
by wallisds (Beadle) on Mar 29, 2012 at 19:22 UTC |