0

Hi All,

I'm having difficulty in getting the data that I need from the DB.. and it is probably my lack of understanding in the query that I created...

data looks like this in the table called RandPtrack


rec_id type group_id open_date close_date orders shares order_date order_num
1 R 96 2012-02-14 22:55:05 2012-02-19 16:44:31 4 25 2012-02-19 16:44:31 123123
2 P 44 2012-02-14 22:55:58 0000-00-00 00:00:00 0 0 0000-00-00 00:00:00 0
4 R 97 2012-02-19 16:44:45 0000-00-00 00:00:00 0 0 0000-00-00 00:00:00 0

$sql_r="SELECT MAX(group_id), rec_id FROM RandPtrack where type='R'";
$result_r=mysql_query($sql_r);
$request_r=mysql_fetch_array($result_r);
$reserve=$request_r[0];
$reserve_rec=$request_r[1];

What I'm expecting to see is the Max group_id, where the type is R, which would be 97.

And the rec_id of 4 which is connected to the record with the max group_id

What I'm getting is the 97 for the max, but I'm getting rec_id 1...


So, what do I need to do to get the rec_id of the record that has the Max group_id ?

Any suggestions would be very helpful

Thanks in advance.

Douglas

Edited by showman13: n/a

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by showman13
0

Try this sql statement instead:

"SELECT group_id, rec_id FROM RandPtrack where type='R' order by group_id desc limit 1"

This will select all records sort them in descending group_id order (with the largest group_id first) and them limit the output to one (the first) record.

0

Try this sql statement instead:

"SELECT group_id, rec_id FROM RandPtrack where type='R' order by group_id desc limit 1"

This will select all records sort them in descending group_id order (with the largest group_id first) and them limit the output to one (the first) record.

That was WAY too easy... Generally that is the answer. The easy one...

Thank you very much. I do have a tendency to make things harder than they need to be.

Again. Thanks, I'm sure that will do what I need.

Douglas

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.