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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -