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):
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
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