Gossamer Forum
Quote Reply
SQL Relation question
I want to select a number of records from two tables using the GT::SQL library. The condition is that all records with the highest id in one table are selected.

To be more precise: let's say I want to select all posts by the user with the highest user_id (which is unknown to me, but anyway it is the highest value in the database). The problem is that I don't know how to select all records which belong to the highest user_id (i.e. something like MAX(user_id))

What I have now (giving all posts of somebody with a specific user_id = 123):
Code:
my $p = $DB->table ('Post');
my $p_u = $DB->table ('Post','User');
my $sth = $p_u->select ( { user_id => 123 } );

while (my $post = $sth->fetchrow_hashref) {
# do something useful here ....
}

How should I change this code to return the posts of the user with the highest user id?

Thanks a lot for your help.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Subject Author Views Date
Thread SQL Relation question yogi 2607 Mar 22, 2002, 8:03 AM
Thread Re: [yogi] SQL Relation question
Alex 2520 Mar 22, 2002, 9:11 AM
Thread Re: [Alex] SQL Relation question
yogi 2550 Mar 22, 2002, 11:23 AM
Thread Re: [yogi] SQL Relation question
Alex 2535 Mar 22, 2002, 1:00 PM
Post Re: [Alex] SQL Relation question
yogi 2511 Mar 22, 2002, 10:05 PM