471,049 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

Help with a join

Hi there,

I was hoping someone could help me out here.

I have a table which has columns seq and price. Some sample rows are...

seq price
1 34
1 35
2 25
2 29
2 31
3 31
4 30
4 31

I would like to return the single row which the largest seq number and
smallest price within that seq group. So for the example above the
second to last row would be returned (seq=4, price=30).

I am running MySQL 4.0.20 so unfortunately I cannot do subqueries.
Would someone be able to suggest how this could be done with joins?

Thanks,
Dom

Jul 23 '05 #1
1 966
ds*********@gmail.com wrote:
I have a table which has columns seq and price. Some sample
rows are...
seq price
1 34
1 35
2 25
2 29
2 31
3 31
4 30
4 31
I would like to return the single row which the largest seq
number and smallest price within that seq group. So for the
example above the second to last row would be returned
(seq=4, price=30).
I am running MySQL 4.0.20 so unfortunately I cannot do
subqueries. Would someone be able to suggest how this could
be done with joins?


The following should help you:

SELECT
MAX(seq), MIN(price)
FROM atable
GROUP BY seq
ORDER BY seq DESC
LIMIT 0,1

I'm running 4.0.17

--
Bart

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by netpurpose | last post: by
28 posts views Thread by stu_gots | last post: by
4 posts views Thread by jimh | last post: by
9 posts views Thread by Dom Boyce | last post: by
5 posts views Thread by Arvin Portlock | last post: by
1 post views Thread by Rahul | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.