Good day,
I'm looking to order my cometchat chats by last sent date (For example: 1 day ago, 3 days ago, 8 days ago, etc..) for a private messaging system i am working to integrate.
However every time i run the command:
(select distinct(f.member_id) id, f.display_name username from
cometchat m1, members f where (f.member_id = m1.from and m1.to = '1')
or (f.member_id = m1.to and m1.from = '1')) order by sent desc
Which is taken from the official cometchat admin panel, i am correctly displayed the information in question (however it's unorganized. It organizes itself by last member id from the members table. instead of that from cometchat.) This is the example: http://i.imgur.com/ZfqAerr.png
Now, if i use the following command:
(select distinct(f.member_id) id,sent, f.display_name username from
cometchat m1, members f where (f.member_id = m1.from and m1.to = '1')
or (f.member_id = m1.to and m1.from = '1')) order by sent desc
It does output the "sent" times from cometchat, but it also ungroups all the messages sent (so it's like page by page, instead of group messaging.) Proof: http://i.imgur.com/dtJegw0.png
So what steps must i take in order to make it so it displays both tables accurately in a grouped format by last sent time?
This is the Cometchat table structure: i.imgur.com/s2Nf8xd.png
This is the members table structure: i.imgur.com/mcq2Pyp.png
Here is SQL that we would suggest to address this issue:
select
distinct(f.member_id) id,
f.display_name username,
max(sent) senttime
from cometchat m1, members f
where (f.member_id = m1.from and m1.to = '1')
or (f.member_id = m1.to and m1.from = '1')
group by f.member_id
order by sent desc
The group_by
keeps messages sent from or to a particular member together.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.