Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL导出聊天表历史记录_Mysql - Fatal编程技术网

MySQL导出聊天表历史记录

MySQL导出聊天表历史记录,mysql,Mysql,我有两个MySQL表: User table (user): user_id, username Chat table (chat): from_user_id, to_user_id, message, timestamp 我想导出聊天历史记录,包括以下字段,并按时间戳asc对结果进行排序: From_user_name, to_user_name, message, timestamp 我尝试了几种编写sql的方法,但没有一种有效。有人能帮上sql吗?谢谢你 您可以尝试以下方法: SE

我有两个MySQL表:

User table (user): user_id, username 
Chat table (chat): from_user_id, to_user_id, message, timestamp
我想导出聊天历史记录,包括以下字段,并按时间戳asc对结果进行排序:

From_user_name, to_user_name, message, timestamp

我尝试了几种编写sql的方法,但没有一种有效。有人能帮上sql吗?谢谢你

您可以尝试以下方法:

SELECT from_user_name, to_user_name, message, timestamp
FROM chat c
join user f on c.from_user_id = f.user_id
join user t on c.to_user_id = t.user_id
order by timestamp asc

展示你已经尝试过的以及为什么没有成功。