Re: optimization
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!
Subject
Written By
Posted
Re: optimization
August 03, 2005 04:01PM
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.