MySQL Forums
Forum List  »  Newbie

Re: Problem MAX(ID) query killing MySQL :)
Posted by: Phillip Ward
Date: April 13, 2016 05:59AM

You don't need the sub-query,
You're already aggregating by legacy_id; within that grouping, you want the largest value of id. That's what max (or any of the aggregating functions) will do when used in conjunction with a "group by" clause.

This should do the job:

select   legacy_id
,        max( id ) as listing_id 
from     ozw_domain1.Listing 
where    legacy_id > 0 
group by legacy_id 
having   count( * ) > 1 ;

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
Re: Problem MAX(ID) query killing MySQL :)
April 13, 2016 05:59AM


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.