mysql - sql distinct function trouble -


i have query

 select m1.mid mid, m1.uid uid, m1.date, m1.body body messages m1 m1.chat_id null , deleted = 0 , m1.date in ( select max(m2.date) messages m2 m2.uid = m1.uid , m2.chat_id null , m2.deleted = 0 ) 

this query not written me, got here - hanks them lot.

but have problem. when there more 1 message same date , uid(from same user) values, 2 or more records same date , uid, i'd have one( no matter which, or message greatest mid f.e.)

i've tried use distinct(uid) no success result. there other way achive result want?

you can use solution find recent message per uid:

select b.* ( select max(mid) maxmid messages chat_id null group uid ) inner join messages b on a.maxmid = b.mid 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -