Exclude user list(s) from list of members (union?)
Your guidance is really appreciated on the following matter.
I am trying to display a list of users (to a user) by eliminating the use开发者_JAVA技巧rs that already exist in other his/her lists.
For example, I want to display all my sites users to a user, minus his blocked list.
I believe I need to use the UNION operator, but have no previous experience in doing so.
would it be something like?
SELECT * FROM myMembers WHERE id='$id'
UNION
SELECT * FROM blocked WHERE id!='$id'
UNION
.
.
.
Just doesn't feel right... My database scheme is:
myMembers
-----------------------
id username
-----------------------
1 x
2 y
3 z
Blocked
---------------------------------------------------------
id mem1 mem2
---------------------------------------------------------
1 2 1
2 4 1
mem2
= the user doing the blocking.
SELECT * FROM myMembers WHERE id NOT IN (SELECT * FROM Blocked WHERE mem2!='$userid')
where userid is the id of the user to whom you are displaying the list
How about the following:
SELECT DISTINCT * FROM myMembers
WHERE id NOT IN (
SELECT id FROM Blocked
WHERE mem2 = '$user_viewing_list'
)
精彩评论