Name

selectcol_arrayref( )

Synopsis

$database_handle->selectcol_arrayref($sql_statement[,
                  \%attributes, @bind_values])

This returns a reference to an array containing a value in the first column of each row selected. The SQL statement is given as the first argument of the function. This can be particularly useful if the first column is a key field. This function performs prepare( ) and execute( ) on the SQL statement.

...
my $sql_stmnt = "SELECT * FROM books";
my $book = $dbh->selectcol_arrayref($sql_stmnt);
foreach my $author_id (@$book){
   print "$author_id \n";
}

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.