1. 需求
根据通知表(tb_notification)中的用户ID(user_id),按时间倒序查询该用户所在房间所有人发出的通知。(用户所在的房间ID需要在用户表(tb_user)中查询)
2. 表结构与部分数据
-
通知表(tb_notification)

-
用户表(tb_user)

3. 查询语句
select * from tb_notification
where
(select room_id from tb_user
where tb_user.id = tb_notification.user_id) =
(select room_id from tb_user
where tb_user.id = 20200011)
order by noti_date desc
4. 结果
5. 前端显示
相关内容
本文介绍了如何通过SQL查询从tb_notification表中获取特定用户(如ID为20200011)所在房间的所有通知,查询结果按时间降序排列。查询涉及到联查用户表tb_user以确定用户房间ID。
1219

被折叠的 条评论
为什么被折叠?



