doucuodan0897 2011-09-15 12:24
浏览 37

从成员列表中排除用户列表(联合?)

Your guidance is really appreciated on the following matter.

I am trying to display a list of users (to a user) by eliminating the users 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.

  • 写回答

2条回答 默认 最新

  • dongtan1845 2011-09-15 12:33
    关注
    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

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度