sql - 为什么这个获取朋友的查询没有返回任何结果?
问题描述
我有一个名为 friends 的表,其中包含 3 列:
user1id, user2id, status
Status
是另一个表的外键,FriendshipStatuses
其他两列都是user
表的外键。
我尝试了一些不同的查询,这些查询导致错误并获得仍在请求中的友谊。我提供的查询没有返回任何结果。
$userId
包含当前登录用户的 id
SELECT
users.username,
users.fullName,
users.user_id
FROM
users
WHERE
users.user_id IN (SELECT user1id, user2id
WHERE user1id = $userId
OR user2id = $userId)
解决方案
这段代码没有做任何有用的事情:
SELECT user1id, user2id
WHERE user1id=$userId
OR user2id = $userId
您在其中缺少具有列FROM
的表或视图user1id
的 a和user2id
。
推荐阅读
- azure-active-directory - 尝试使用 OpenID 和 dotnetopenauth 登录 Azure AD,但得到“未找到 OpenID 端点”。
- java - Spring Boot - 根据标志通过本地数据库或 Active Directory 进行身份验证
- php - CakePHP 3 将 .ctp 模板输出为 CSV 文件
- java - Java:尝试使用可实例化的类和数组打印每 3 周的平均温度
- swift - var a = 5 和 var a = Int(5) 有什么区别?
- python - 当我从我的数据库中提取主键时,它们会出现在括号中,我以后无法在我的代码中使用它们
- android - 如何使用设备场为 BOOT_COMPLETED 和 USER_PRESENT 接收器创建自动化测试?
- python - Colab教程使用object_detection进行迁移学习,为什么lookup_ops.py中出现TypeError?
- ansible - 获取ansible mongo模块的IP
- java - 使用类路径外的配置文件创建 CacheManager bean