mysql - Order by not working as expected after using group by -


i attempting list of messages, grouping from_user_id , to_user_id screenshot below. only, problem not seem ordering recent.

here's screenshot showing how look:

enter image description here

query: select

select  concat(to_user_id, from_user_id) group_by, pm.* personal_messages pm (to_user_id = 1265) or (from_user_id = 1265) group group_by order id desc 

table structure:

enter image description here

you need add date value query:

select concat(to_user_id, from_user_id) group_by,        max(updated_at) max_updated_at personal_messages pm (to_user_id = 1265) or (from_user_id = 1265) group group_by order max_updated_at desc 

the date value created_at or updated_at, depends on actual requirement. have use aggregate function max though, because neither of these fields appears in group by clause.


Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

Command prompt result in label. Python 2.7 -