Hi
I have two tables - one where an administrator talks to a user in a chat session and vice versa. I would have liked to put the chats in one table - but the login characteristics of the admin are different then the non login of casual chat users - so I just did two tables.
I wish to display the chat history between the two types of users using the Id of each as they are logged in on their respective session.
How can I join by the two types and select their chat history where to user in one table = equals from user in the other … and then sort by the most recent timestamp in Either table to get a chronological display of their chat?
I tried inner joins and left joins but couldn’t seem to g et it to work
Something like select * from admin_chat_message and select * from user chat message where a.to_user = u.from user or u.to_user = a.from_usee by sort by timestamp
… where timestamp is the most recent in either table.
Pls see sample tables below:
(Really the objective is to just the chat history of both user types sorted in reverse chronological order)
TABLES
admin chat message (
id int not bull auto_increment
to_user_id int not null
from_user_id int not null
chat-message text not null,
timestamp timestamp not null autonincremnt default current_timestamp(),
status int(1) not null,
Primary Key (id)
):
user_chat_message (
id int not null auto_increment
to_user_id int not null
from_user_id int not null
chat-message text not null,
timestamp timestamp not null autonincremnt default current_timestamp(),
status int(1) not null,
Primary Key (id)
):