in reply to (jeffa) Re: building Drop down menu - from a flat file
in thread building Drop down menu - from a flat file

well i had tried the DBI::CSV before i posted this question and i did the same thing you say here BUT when i try to use the DISTINCT in my SQL it does not seem to return the desired result?

Here is what i had:

#!/usr/local/bin/perl use DBI; my $dbh = DBI->connect( "DBI:CSV:f_dir=/export/home/temp;csv_eol=\n;csv_sep_char=!; +", {RaiseError=>1}, ); $dbh->{'csv_tables'}->{'datainfo'} = { 'file' => 'datainfo.data', # 'sep_char' => "!", 'quote_char' => undef, 'escape_char' => undef, 'col_names' => ["id", "class", "name", "instructor"] }; my ($query) = "select distinct id, class from datainfo "; my ($sth) = $dbh->prepare($query); $sth->execute(); while (my $row = $sth->fetchrow_hashref) { print ("ID =", $row->{'id'}, "\n\t CLASS = ", $row->{'class'} +, "\n"); } print "\n";
you know i just say a mistake in my code, and when i tried to run it with just one column in the select it ran correctly! I wonder if DBI::CSV does allow mutilple columns to be listed with a DISTINCT

Replies are listed 'Best First'.
(jeffa) 3Re: building Drop down menu - from a flat file
by jeffa (Bishop) on Jul 25, 2002 at 05:34 UTC

    This is a SQL issue, not a DBI::CSV issue. DISTINCT only eliminates those rows where all of the selected fields are identical. You could eliminate more rows by specifying the GROUP BY keywords, but i doubt you really want to do that ... consider either normalizing your data or using a hash solution instead.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)