0

我的两张桌子就像

Table 1


uid     mail


1136    xxx@gmail.com
1231    xxx@ymail.com

Table 2

uid     rid

1136    3
1136    7
1231    5
1231    2

所以我想加入这两个表,并希望得到表 2 中的 rid 不等于 3 的结果 uid。

如果您不理解我的要求,请告诉我。

4

2 回答 2

2
select t1.uid, mail, rid
from table1 t1
join table2 t2
on t1.uid = t2.uid and t2.uid not in (select uid from table2 where rid = 3)
于 2013-07-23T09:25:13.137 回答
0
select t1.uid, mail, group_concat(rid) as rids
from table1 t1
left join table2 t2
on t1.uid = t2.uid
group by t1.uid
having not find_in_set(3,rids)
;

小提琴

于 2013-07-23T12:41:33.003 回答