【发布时间】:2017-08-24 16:20:30
【问题描述】:
我有两个表 table1(userid,regid) 和 table2(userid,hostuserid,status),其中 userid 或 hostuserid 等于 myuserid(已经包含在变量 $userid 中)。我想找到 table1 中的所有行,这样 table1 .userid!=table2.userid AND table1.userid!=table2.userid。
table1
--------
userid regid
1 gbjnknnk
2 bvgcghb
3 bjbnjb
table2
-------
userid hostuserid
1 5
5 2
$userid=5
查询应该只返回一行=> 3 bjbnjb 如何实现相同。 我尝试过的
SELECT * FROM table1 JOIN table2 WHERE (table1.userid!=table2.userid AND
table2.hostuserid=$userid) AND (table1.userid!=table2.hostuserid AND
table2.userid=$userid)
【问题讨论】:
-
如果你想要不匹配的东西,那么你不是在寻找连接......我猜你想要一个使用
where table1.userid not in(select userid from table2) and table1.userid not in (select hostuserid from table2)的子查询