Subquery errors when retrieving different arrays

advertisements

I ran the query below and had the error

sub-query returns multiple rows

I have replaced all the sub query in with any, and = as well. Yet the problem is not solved.

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;


The only obvious (to me) subquery that could cause this is:

 (select PalUserId from UserPals
       where UserId = UserId_Param and FriendStatus = 1)

Perhaps you want exists:

exists (select PalUserId from UserPals
        where UserId = UserId_Param and FriendStatus = 1
       )

As an aside, it seems a bit strange to mix = any () and in.