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. 结果
![](https://i-blog.csdnimg.cn/blog_migrate/a85b9d4546cd496be914876680fd2d9b.png)
5. 前端显示
![](https://i-blog.csdnimg.cn/blog_migrate/99427c41010ab4f88e24410f18db4a01.png)
相关内容