MySQL Forums
Forum List  »  Newbie

Re: optimization
Posted by: Roland Bouman
Date: August 03, 2005 04:01PM

Yes, you can.
For virtually every version, you can either stick to what you're doing now or do this:

select t1.*
from t as t1
cross join t as t2
group by t1.col1
, t1.col2
, ...all other columns of t1...
having t1.datacol = max(t2.datacol)

(which would probably perform a lot worse than you original solution)

For mysql>= 3.23.6. you can solve it in two queries, using a user variable:

select @max_date := max(datacol)
from t as t1;

select *
from t as t1
where datecol = @max_date;


If you have a MySQL >= 4.1, you can use a subquery:

SELECT *
FROM t as t1
WHERE ...
AND datecol = (
SELECT max(datecol)
FROM t as t2
)

Hop it helps you, good luck!

Options: ReplyQuote


Subject
Written By
Posted
August 03, 2005 03:42PM
Re: optimization
August 03, 2005 04:01PM
August 03, 2005 04:05PM
August 04, 2005 07:30AM
August 04, 2005 08:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.