0

i have a table in my phpmyadmin database with this colomn and data:

id    sensor    temp    hum    date

--------------------------------------

1     sensor1   15      20     20/12/2016
2     sensor1   18      0      2/10/2015
3     sensor2   22      10     20/12/2016
4     sensor2   30      22     2/10/2015
5     sensor3   25      15     20/12/2016

I want a query that return data like:

id    sensor    temp    hum    date

--------------------------------------

1     sensor1   15      20     20/12/2016
3     sensor2   22      10     20/12/2016
5     sensor3   25      15     20/12/2016

So i want for each sensor, the most recent date and information. How can i do this with a query? Thanks all for help.

EDIT

My date are store in this format:

Thu Sep 29 2016 11:42:59 GMT+0200 (CEST)

EDIT2

I have notated that on my db is activated the only_full_group_by

1

1 Answer 1

1

Try

select `id`,`sensor`,`temp`,`hum`, max(`date`)
from table
GROUP BY  `sensor`;
Sign up to request clarification or add additional context in comments.

3 Comments

I have try your query without 'id' because it isn't important for my aim, it return me an error like: #1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'WiFiNetwork.WiFiTH.temp' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
try add temp and hum to group by clause as well
it dont return any error, but it return me all the table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.