mysql - Group by query with max column -


I want to ask the last chat group grouped by a certain user's chat partner. My current query works, though it chooses the user's own message according to the order stemmed by the timestamp. But I want to send the previous messages to other users to order this specific user timestamp

Here is my bella:.

Expected Result: 2 rows

  ... messages -------------------- ... r for me last ... I finally  

I have created chat messages and message with the greatest timestamp " x last called "

My current question is:

sELECT a *, DU.user username, DU.photo, DU.city, DU.year, DU.month, DU.day Join an intermediate from db_chats (selection max (timestamp) ts, user, companion du State db_chats Group partner) A.timestamp = T.ts and A.user = T.user include db_users T T.partner = DU.id Left which DU where A.user = 'order timestamp Dis by RGXiLkVpKGc4FSU7SeyMlZ7z' A < / code>

you can use the query to get the query ULT:

  select a *, DU.user username, DU.photo, DU.city, DU.year, DU.month, DU.day db_chats as one, db_users DU where timestamp (max ( Timestamp) Select from db_chats where partner = "RGXiLkVpKGc4FSU7SeyMlZ7z" user Group) and describes the order by a.USER = DU.ID timestamp  

Edit

The reason is that your original query works not join in is due within:

  select max (timestamp) ts, user, my fellow db_chats Group  

The result of this query is:

  | TS | USER | Partners | | ------------ | -------------------------- | --------- ----------------- | | 1414453415 | XAlX66JQfmsOcotg00wPsZfx | RG XiLkVpKGc4FSU7SeyMlZ7z | | 1414453387 | RG XiLkVpKGc4FSU7SeyMlZ7z | XAlX66JQfmsOcotg00wPsZfx | | 1414443546 | RG XiLkVpKGc4FSU7SeyMlZ7z | YZQF4hbvyjbS0p7wYIR2Hkq9 |  

If you check your DB_CHITES table (below), you can not get your demand message in those time stamps. Therefore the query will never return "last from me"

  | USER | Partners | Message | TIMESTAMP | | -------------------------- | ---------------------- ---- | -------------- | ------------ | | XAlX66JQfmsOcotg00wPsZfx | RG XiLkVpKGc4FSU7SeyMlZ7z | R for me 1414443447 | | YZQF4hbvyjbS0p7wYIR2Hkq9 | RG XiLkVpKGc4FSU7SeyMlZ7z | Me meter 1414442845 | | YZQF4hbvyjbS0p7wYIR2Hkq9 | RG XiLkVpKGc4FSU7SeyMlZ7z | Last time for me 1414453415 | | RG XiLkVpKGc4FSU7SeyMlZ7z | XAlX66JQfmsOcotg00wPsZfx | Me r 1414453387 | | RG XiLkVpKGc4FSU7SeyMlZ7z | YZQF4hbvyjbS0p7wYIR2Hkq9 | Me m 1414443546 | | XAlX66JQfmsOcotg00wPsZfx | RG XiLkVpKGc4FSU7SeyMlZ7z | Last for me 1414453234 |  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -