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 5976839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:17:06+00:00 2026-05-22T21:17:06+00:00

I am designing a message/comment table in MySQL for social networking site. I have

  • 0

I am designing a message/comment table in MySQL for social networking site. I have a messaging system where participating two users (only two and not more than that) will have single/unique thread. So, whenever a user is messaging another user then it will check whether both user had unique thread IF NOT then it will create unique thread for both user.

create table comment_threads (
thread_id int (PK),
user_id_1 int,
user_id_2 int,
created datetime
);

create table comments (
comment_id int (PK),
thread_id int (FK),
comment text,
created datetime
);

Whenever a user messages another user each time then I have to check whether both of the participating user had previous thread so i have to query the database for that (QUERY 1). And then again if there wasn’t any thread to create a thread in comment_thread (QUERY 2). Then again to post comment in comment table (QUERY 3). So I have to query two or three times for messaging.

Questions:

  1. Is the above tables correct way of solving my problem or it needs some correction?
  2. Is there any other better way to do it?
  • 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-22T21:17:07+00:00Added an answer on May 22, 2026 at 9:17 pm

    You don’t really need to have 2 tables.. 1 table should be fine:

    create table comments (
    comment_id int (PK),
    parent_id int,
    user_id_1 int,
    user_id_2 int,
    comment text,
    created datetime
    );
    

    For a new thread, set the parent_id to 0. For future comments, you can set the parent_id to the ID of first comment.

    This way, you can also do multi-level threaded conversations, and it makes it easy to do stuff like ‘comments I’ve posted’.

    As per Itay’s answer, you should use some caching mechanisms to improve performance.

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

Sidebar

Related Questions

I'm designing a messaging system that will have to support a huge amount of
I am designing a message system. In the table where I store the messages,
When designing user table what would be the must have fields from the security/user
I have a message Queue and I am designing a WPF interface for it.
I have a pretty large social network type site I have working on for
I'm designing a C#/NHibernate website that features a private messaging system. I would like
I'm sure this is a basic OOP question -- I'm designing a message-passing system
I'm designing a database containing messages and messengers. create table Message( MessageID int, MessengerID
I am presently designing a message queue system that will be used by various
I am currently designing a chatting system. How can I have a sound play

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.