----- Original Message -----
From: "Eric Anderson" <keric@stripped>
To: <mysql@stripped>
Sent: Tuesday, October 20, 2009 4:05 PM
Subject: Re: Distinct max() and separate unique value
>>> I'm trying to formulate a query on a Wordpress database that will give
>>> me the highest 'object_id' with the highest 'term_taxonomy_id',
>>> something like:
>>>
>>> +-------------------------+------------------+
>>> | max(distinct object_id) | term_taxonomy_id |
>>> +-------------------------+------------------+
>>> | 1503 | 127 |
>>> | 1494 | 122 |
>>> +-------------------------+------------------+
>>>
>>> But I just can't seem to get there?
I confess I did not understand what you are trying to do.
If what you actually want is the highest 'term_taxonomy_id' for each
distinct objhect_id then the query would be:
select object_id, max(term_taxonomy_id)
where term_taxonomy_id IN (122,127)group by object_id
order by object_id desc;
This query will not take into consideration term_taxonomy_Id values other
than 122 and 127, it also will not return object_id's without a
term_taxonomy_Id value of 122 or 127.