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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:39:15+00:00 2026-05-27T07:39:15+00:00

For the last couple of weeks I’ve been working on a web based chat

  • 0

For the last couple of weeks I’ve been working on a web based chat client application and I have a question regarding storing chat messages inside a MySql table. I created a table called conversations and for now it consists of 5 fields;

user1ID, user2ID ,messages(mediumtext), status, timestamp.

When I test the chat application everything works perfectly fine, but the problem is every time a user sends something, I’m appending that value into my ‘messages’ field as a new line. And when it comes to retrieving the message, my sql code reads the whole thing and show it to the corresponding user. So the amount of data linearly increase by the amount of text added into the messages field.
My question is, is there any way to SELECT only the last line from a text field or maybe another solution that will reduce the amount of transferred data.

  • 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-27T07:39:16+00:00Added an answer on May 27, 2026 at 7:39 am

    You need a better db schema – more relational. Doing so will give you some other improvements as well (password protected chats and multi-user chat to name a couple)

    Here is one take on an ERD for your db.

    enter image description here


    5/6/2016 edit
    Adding DDL with (hopefully) improved field types and names

    CREATE TABLE user
    (
        user_id CHAR(32),
        user_login VARCHAR(255),
        user_password CHAR(64),
        user_email VARCHAR(400),
        PRIMARY KEY (user_id)
    );
    
    CREATE TABLE message
    (
        message_id CHAR(32),
        message_datetime DATETIME,
        message_text TEXT,
        message_chat_id CHAR(32),
        message_user_id CHAR(32),
        PRIMARY KEY (message_id)
    );
    
    CREATE TABLE user_chat
    (
        user_chat_chat_id CHAR(32),
        user_chat_user_id CHAR(32),
        PRIMARY KEY (user_chat_chat_id,user_chat_user_id)
    );
    
    CREATE TABLE chat
    (
        chat_id CHAR(32),
        chat_topic VARCHAR(32),
        chat_password CHAR(64),
        user_chat_user_id CHAR(32),
        PRIMARY KEY (chat_id)
    );
    
    CREATE INDEX user_login_idx ON user (user_login);
    ALTER TABLE message ADD FOREIGN KEY message_chat_id_idxfk (message_chat_id) REFERENCES chat (chat_id);
    
    ALTER TABLE message ADD FOREIGN KEY message_user_id_idxfk (message_user_id) REFERENCES user (user_id);
    
    ALTER TABLE user_chat ADD FOREIGN KEY user_chat_user_id_idxfk (user_chat_user_id) REFERENCES user (user_id);
    
    ALTER TABLE chat ADD FOREIGN KEY chat_id_idxfk (chat_id,user_chat_user_id) REFERENCES user_chat (user_chat_chat_id,user_chat_user_id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a couple of weeks now, I have been working on migrating my client
I have been working on Flex for last couple of months and as this
I have been studding GIT for the last couple of weeks in an attempt
I've been trying to create an android-application the last couple of weeks, and mostly
i have been getting into rails over the course of the last couple weeks
I've been working with the Restlet library for the last couple weeks and from
For the last couple of months I have been writing an intranet site for
I've been writing a c# program for the last couple weeks and the text
Over the last couple of weeks i have come across lots of articles about
Well from last couple of weeks I am developing an application using html, javascript

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.