Doulbe<>任何查询无法处理第二个<> ANY

时间:2015-06-18 02:24:27

标签: mysql sql select any

尝试创建一个生成以下用户列表的查询:

A。)登录用户尚未关注

B中。 )登录用户尚未查看和跳过(FOLLOWER_SWIPES表)

以下是我的查询,由于某种原因,它仍然向用户显示过去登录用户已跳过:

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 个答案:

答案 0 :(得分:0)

条件:

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

不是一个非常严格的条件。尝试使用ALL代替ANY

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

或使用等效物:

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