我运行下面的查询并出现错误
sub-query returns multiple rows
我已将所有子查询 in
替换为 any
和 =
。但问题还没有解决。
SELECT *
from UserPost
where UserId = UserId_Param
or UserId = any (select UserId from UserPals
where PalUserId = UserId_Param and FriendStatus = 1)
or UserId = any (select PalUserId from UserPals
where UserId = UserId_Param and FriendStatus = 1)
and privacy = 1
and PostId not in (select PostId from UserHidePost where UserId = UserId_Param)
and Committed = 1
and Trashed = 0
union all
select *
from UserPost
where privacy = 2
and PostId = any(select PostId from PostCategory
where PalCategoryId = any (select UserPalCategoryId
from PalCategory
where userId = UserId_Param
or PalUserId = UserId_Param))
and PostId not in(select PostId from UserHidePost
where UserId = UserId_Param)
and Committed = 1
and (UserId = any (select UserId from UserPals
where PalUserId = UserId_Param and FriendStatus = 1)
or (select PalUserId from UserPals
where UserId = UserId_Param and FriendStatus = 1))
and Trashed = 0
LIMIT lim_val OFFSET lim_offset;
最佳答案
唯一明显的(对我来说)可能导致这种情况的子查询是:
(select PalUserId from UserPals
where UserId = UserId_Param and FriendStatus = 1)
也许你想要存在
:
exists (select PalUserId from UserPals
where UserId = UserId_Param and FriendStatus = 1
)
顺便说一句,混合使用 = any ()
和 in
似乎有点奇怪。
关于php - 从不同表获取时子查询出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31184416/