Doulbe <> ANY query not working on second <>ANY

45 views Asked by At

Trying to create a query that generates a list of users that :

A.) the loggedin user is not already following

B. ) the loggedin user has not already viewed and skipped ( FOLLOWER_SWIPES table)

Here is my query, for some reason it is still showing users that the loggedin user has skipped in the past:

SELECT u.uid, u.full_name, u.bio, u.thumb_img, u.college, u.HEADER_IMG
FROM users AS u
WHERE u.uid <>'$uid'
AND u.uid <> ANY(

SELECT FOLLOWING_UID_FK
FROM FOLLOWERS
WHERE UID_FK='$uid'
)
AND u.uid <> ANY(
SELECT SWIPPED_UID_FK
FROM FOLLOWER_SWIPES
WHERE UID_FK =$uid
)
AND u.college_id='$college'
ORDER BY u.last_feed_load DESC
LIMIT 0 , 30
1

There are 1 answers

2
Gordon Linoff On

The condition:

AND u.uid <> ANY(
SELECT SWIPPED_UID_FK
FROM FOLLOWER_SWIPES
WHERE UID_FK =$uid
)

is not a very restrictive condition. Try using ALL instead of ANY:

AND u.uid <> ALL (SELECT SWIPPED_UID_FK
                  FROM FOLLOWER_SWIPES
                  WHERE UID_FK = $uid
                 )

Or use the equivalent:

AND u.uid NOT IN (SELECT SWIPPED_UID_FK
                  FROM FOLLOWER_SWIPES
                  WHERE UID_FK = $uid
                 )