D
D
Dmitry Skogorev2015-10-27 01:35:54
MySQL
Dmitry Skogorev, 2015-10-27 01:35:54

How to write a query with a selection of unique values?

I have a table ala
uid, data, time
with values
​​1,7,9
1,7,12
2,6,12
2,9,16
3,4,13
1,3,15
respectively, I want to get unique values ​​for each uid at the maximum time
, that is, the output is:
3,4,13
1,3,15
2,9,16
in the case of one uid - there are no problems - I take max(time) or order by `time` desc limit 1
and with several something the head does not understand.
Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wol_fi, 2015-10-27
@EnterSandman

select max(time), uid, data from test group by uid
Don't forget only index on uid

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question