MySQL Forums
Forum List  »  Newbie

Re: Max Query Issue
Posted by: Felix Geerinckx
Date: May 20, 2005 01:32PM

JOHN FARRUGIA wrote:
> I read the manual but I'm not sure what it means.
> the id column is the only column in the table that is unique. the value column may have more then
> one entry with the same value. I am just looking for the largest value within my time range.

> Can you help write a query statment?

In your query:

Select
id,reference,max(value)
from data_readings.lts4a_accel_torquer
where reference='total_parts' group by reference;

id is a so-called hidden field (it doesn't appear in the GROUP BY clause). The manual states:

Do not use this feature if the columns you omit from the GROUP BY part are not unique in the group! You get unpredictable results.

And that is exactly what is happening to you.

If you are using MySQL 4.1.x (so you can use subqueries), the solution to your problem is solved at the top of http://dev.mysql.com/doc/mysql/en/example-maximum-column-group-row.html.

For MySQL prior to 4.1.x, you can use a temporary table or the MAX-CONCAT trick (both methods are also explained at the above url.

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
May 20, 2005 11:19AM
May 20, 2005 11:28AM
May 20, 2005 12:17PM
Re: Max Query Issue
May 20, 2005 01:32PM
May 20, 2005 01:58PM
May 20, 2005 02:19PM
May 20, 2005 02:28PM
May 20, 2005 02:36PM


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.