Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6680021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:25:36+00:00 2026-05-26T04:25:36+00:00

I have a messages table messages ————– user_id_from (int) user_id_to (int) text (varchar) date

  • 0

I have a messages table

messages
--------------
user_id_from (int)
user_id_to (int)
text (varchar)
date (datetime)
isRead (boolean)

I want to get messages activity for user where inbox and outbox are in one list (same as facebook messages). I want to get the last message for each user I contact. I tried to do this:

lets say this is my data

user_id_from   user_id_to  text      date      isRead
100            101         "text1"   2011/1/1  0
101            100         "text2"   2011/1/2  0
100            102         "text3"   2011/1/5  0

Here’s my query:

select *
 from Message m 
 where m.user_id_to = 100
   or m.id in 
     (select m2.id 
      from Message m2 
      where m2.user_id_from = 100 
        and m2.user_id_to != m.user_id_from
     )
 group by m.user_id_from, m.user_id_to

This query gives me the complete messages where user 100 is there.

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:25:36+00:00Added an answer on May 26, 2026 at 4:25 am

    This would require you to keep track of ‘threads’ in messages, or you could also call them conversations. Every time you send a message, it gets a conversation_id. Then, you make a table of user_conversation_subscriptions. Sending a message to someone starts a new conversation, with the sender and receiver as the only participants, but they could invite people into the conversation. Than, you could get the new messages grouped by conversation to see in which conversation you’ve got new messages, that’s how it works on facebook.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table messages with two foreign key: user_id_from and user_id_to . I need
I have a simple mysql table called messages with the following fields: ID(int) MESSAGE(varchar)
I have the following table: Messages ID(PK) int auto_inc Message varchar(100) I would like
i have a stack of messages in database table. i want to send these
I have a table Messages with columns ID (primary key, autoincrement) and Content (text).
I have a mysql table containing messages: id (INT) sender_id (INT) recipient_id (INT) sent_time
For a messages table with the following structure id, sender_id, receiver_id, text I want
well i have this messages table with sample values like these: msg_id recipient_id read
I have an Oracle table which contains event log messages for an application. We
I have this in a MySQL db: table Message sender_id int recipient_id int created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.