[英]How to select from table with check if exist on another table?
I have two table which ALLUSER
and BLACKLISTNUMBER
我有两个表,其中ALLUSER
和BLACKLISTNUMBER
select tel_number, telnumber_id, from alluser
How to not select if number is in Blacklist? 如何不选择号码是否在黑名单中?
USE NOT IN : 请勿在以下位置使用:
select tel_number, telnumber_id, from alluser
where tel_number not in
( select tel_number from BLACKLISTNUMBER where
tel_number is not null )
Use not in
something like: not in
使用:
select tel_number, telnumber_id from alluser
where tel_number not in (select tel_number from blacklist);
Or may be NOT EXISTS
: 或可能NOT EXISTS
:
select tel_number, telnumber_id from alluser t
where not exists (select tel_number from blacklist where tel_number = t.tel_number);
Lots of ways to accomplish this. 有很多方法可以做到这一点。 You can use a join as well... 您也可以使用联接...
select a.tel_number,
a.telnumber_id
from alluser a
left join blacklist b on a.tel_number = b.tel_number
where b.tel_number is null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.