gpt4 book ai didi

消息系统的Mysql查询。一个我想不通的小错误

转载 作者:行者123 更新时间:2023-11-29 04:52:35 24 4
gpt4 key购买 nike

我设置了一个基本的消息传递系统,我使用相同的查询来显示已发送和已接收的消息。它工作得很好,但我需要获取 exp 和 dest 的 fbook 字段。我想创建两个查询,如果用户发送了他正在查看的消息,则使用一个查询;如果已收到消息,则使用另一个查询,但也许有更好的方法。

+-----+------+------+----------+----------------+---------------------+------+
| id | exp | dest | message | msg_title | timestamp | view |
+-----+------+------+----------+----------------+---------------------+------+
| 114 | 243 | 245 | From 243 | Message to 245 | 2012-04-04 09:26:52 | 0 |
+-----+------+------+----------+----------------+---------------------+------+

查询

SELECT a.*, b.fbook FROM messages a 
JOIN users b ON a.exp=b.id
WHERE a.id = 114;

用户表

+------------------------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+--------------+------+-----+---------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(50) | NO | | NULL | |
| fbook | bigint(64) | YES | | NULL | |
+------------------------+--------------+------+-----+---------------------+----------------+

最佳答案

你想做这样的事情:

SELECT a.*, b.fbook AS `exp-fbook`, c.fbook AS `dest-fbook`
FROM messages a
JOIN users b ON a.exp=b.id
JOIN users c ON a.dest=c.id
WHERE a.id = 243

关于消息系统的Mysql查询。一个我想不通的小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10006167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com