Giúp mình về csdl web chat simple

Mình có 3 table như sau:

1.table user(
id_user int(11) not null primary key auto_increment,
username varchar(100) not null,
password varchar(100) not nul
);

2.table msg(
id_msg int(11) not null primary key auto_increment,
message text not null,
time int(11) not null,
id_user int(11) not null,
foreign key(id_user) references user(id_user)
);

3. table msg_replay(
id_replay int(11) not null primary key auto_increment,
message text not null,
time int(11) not null,
id_user int(11) not null,
foreign key(id_user) references user(id_user)
);

trường hợp này là mình chat 2 người:
khi chat người 1 sẽ insert vào table msg, người 2 sẽ insert vào table msg_replay.
Mình muốn là câu lệnh select gộp 2 trường là message và time của 2 table với where = id_user
để mình có thể xuất dữ liệu theo thứ tự chat dựa vào trường time ( giống kiểu chat như facebook).

mấy bạn chỉ mình với ( mấy bạn có thể sửa lại csdl, vì mình làm ko bik đúng ko).
ví dụ:
phat: hello ( table msg)
phat: how are you ? ( table msg)
admin: i'm fine ? (table msg_replay). thanks các bạn.
 

Thống kê

Chủ đề
100,756
Bài viết
467,591
Thành viên
339,853
Thành viên mới nhất
THPT Lí Thường Kiệt
Top