gpt4 book ai didi

php - mysql查询帮助?

转载 作者:行者123 更新时间:2023-11-29 04:58:53 28 4
gpt4 key购买 nike

(
SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m.dt
FROM relationships r
JOIN notes m ON m.user_id = r.leader
JOIN user u ON r.leader = u.user_id
WHERE r.listener ='2'
)


UNION ALL
(
SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m.dt
FROM notes m
JOIN user u ON m.user_id = u.user_id
WHERE u.user_id ='2'
)
WHERE dt > '2010-09-20_131830'
ORDER BY dt DESC

这个 deos 是什么,它查询用户(登录)、他们关注的人并检索他们的消息。表格如下所示,!

我想添加到此查询的是用户(登录)更新。但显然用户不关注自己。最好的方法是什么!!

用户表

 user_id | username
-------------------
1 | solomon
2 | muna

消息表

id    user_id| message
---------------------------------------
1 1 | this is my first message
2 1 | this is my second message
3 2 | this is muna message

关系表

leader | follower
------------------
1 | 2

最佳答案

这个怎么样:

SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m.dt
FROM notes m
INNER JOIN user u
ON m.user_id = u.user_id
WHERE (m.user_id = '".$_SESSION['user_id']."'
OR m.userID IN (
SELECT r.leader
FROM relationships r
WHERE r.listener ='".$_SESSION['user_id']."'))

关于php - mysql查询帮助?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3762948/

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