仅当两个用户都是 sql server 的朋友时如何获取数据

问题描述

这是我的数据库结构。 用户表 -用户身份 -fname -lname

个人资料表 -profile_user_id -profile_id -profile_id

friend_request 表 -ID -from_id -to_id -地位 我的查询是 SELECT fname,lname,profile FROM user LEFT JOIN profile ON user.user_id = profile.profile_id WHERE(SELECT status FROMfriend_request WHERE status = 'friend')

解决方法

试试这个:

 SELECT fname,lname,profile FROM user 
 INNER JOIN profile ON user.user_id = profile.profile_id 
 INNER join user 'friend' on friend.user_id = = profile.profile_id
 INNER JOIN friend_request ON friend_request.from_id = user.user_id and  friend_request.to_id = friend.user_id 
 WHERE status = 'friend'

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...