Hi Guys,
I have a sql statement that i need modded, and I'm not quite sure the best way to get the results I need.
SELECT tmm.message_id, tmm.content_id, tmm.sender_id, tmm.new, tmm.replied, tmm.flagged, tmm.sent_date, tmm.viewed_date, tmmc.subject, tmmc.category, tmmc.body, tmcc.first_name, tmcc.middle_name, tmcc.last_name
FROM tbl_member_messages tmm
INNER JOIN tbl_member_messages_content tmmc on tmm.content_id = tmmc.content_id
INNER JOIN members.dbo.tbl_member_core_contact tmcc on tmm.sender_id = tmcc.member_id
WHERE (tmm.recipient_id = <cfqueryparam value="#session.myid#">) and (recipient_deleted <> 1) and (recipient_purged <> 1) and (spam <> 1)
I'm writing a small messaging app, and this is the sql statement for the 'inbox' and it fetches all messages that apply. It works as right now, each new message from another member would get it's own row, but I only want to fetch the 'newest' message.
For instance, say user 'johndoe' send me 'techboyjk' 5 messages. The sql statement above would list each message in the inbox. However, I only want to fetch the newest message from each user, and order the result set by date.
Thoughts?
I have a sql statement that i need modded, and I'm not quite sure the best way to get the results I need.
SELECT tmm.message_id, tmm.content_id, tmm.sender_id, tmm.new, tmm.replied, tmm.flagged, tmm.sent_date, tmm.viewed_date, tmmc.subject, tmmc.category, tmmc.body, tmcc.first_name, tmcc.middle_name, tmcc.last_name
FROM tbl_member_messages tmm
INNER JOIN tbl_member_messages_content tmmc on tmm.content_id = tmmc.content_id
INNER JOIN members.dbo.tbl_member_core_contact tmcc on tmm.sender_id = tmcc.member_id
WHERE (tmm.recipient_id = <cfqueryparam value="#session.myid#">) and (recipient_deleted <> 1) and (recipient_purged <> 1) and (spam <> 1)
I'm writing a small messaging app, and this is the sql statement for the 'inbox' and it fetches all messages that apply. It works as right now, each new message from another member would get it's own row, but I only want to fetch the 'newest' message.
For instance, say user 'johndoe' send me 'techboyjk' 5 messages. The sql statement above would list each message in the inbox. However, I only want to fetch the newest message from each user, and order the result set by date.
Thoughts?
