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.
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.
5/6/2016 edit
Adding DDL with (hopefully) improved field types and names