Ryan/Gerald (!)
(Ryan) You don't want to use selectall_hashref because, as is the nature of hashes,
the key must be unique, which means the database table's key field that provides it must also be unique. If you get this working, you will retrieve a single record for each possible value of each key: presumably 'yes', 'no', '', and NULL or something like that.
I know. One of my key columns is an ID field so there will be a unique key. It does look though as if you're pulling all your database data into a Perl
hash and trying to interrogate that. Surely, in your example above, you should be writing somthing such as: my $data = $dbh->selectall_arrayref(qq( SELECT id, medication FROM table WHERE col1 = 'yes' OR OR col1 = '' OR col1 IS NULL ORDER BY id )); foreach my $row (@$data) { printf "%s: %s\n", @$row; }
nope: my $href =$$dbh->selectall_hashref(q{SELECT * FROM recommendations WHERE RxNumber=? ORDER BY medCategory, Medication, methodPreference}, [qw( medCategory Medication include ifFollowedProtocol ifCycling ID) ], undef,('12345')); So I'm still confused about what I need to do. I want to: 1. display the rows with ifFollowedProtocol eq '' or 'yes' in order of medCategory 2. display the rows with ifFollowedProtocol eq '' or 'no' in order of medCategory I thought I could do this with a hash of hashes...I know there are other ways, but I'd like to understand how to do it with this hashref using hash slices if it's possible. Thanks!