Gossamer Forum
Home : General : Databases and SQL :

Help required converting SQL to GT::SQL::Relation

Quote Reply
Help required converting SQL to GT::SQL::Relation
Can anyone give me a bit of help converting the following SQL into a Links format. I've read the help, but I just can't get my head round what I need to do.

The original SQL is

select corr_time, adm_tech_p, adm_supervisor_p, adm_admin_p, cus_first_name, cus_last_name from wd_correspondence, wd_customers where corr_cus_id_fk = cus_id AND corr_help_id_fk = 63 order by corr_time desc limit 1;
Quote Reply
Re: [davidnavigator] Help required converting SQL to GT::SQL::Relation In reply to
Hi,

Sure:

my $rel = $db->table('wd_correspondance', 'wd_customers'); # Assuming wd_ isn't your table prefix, if it is, remove wd_
$rel->select_options('order by corr_time desc', 'limit 1');
my $sth = $rel->select([qw/corr_time adm_tech_p adm_supervisor_p adm_admin_p cus_first_name cus_last_name/], { corr_help_id_fk => 63 });
while (my $res = $sth->fetchrow_hashref) {
print "Result: $res->{cus_first_name}\n";
}

Hope that helps,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Help required converting SQL to GT::SQL::Relation In reply to
Many thanks. :)