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.