Solution
Solution

Reputation: 162

How to select from table with check if exist on another table?

I have two table which ALLUSER and BLACKLISTNUMBER

select tel_number, telnumber_id, from alluser

How to not select if number is in Blacklist?

Upvotes: 0

Views: 209

Answers (3)

PPJN
PPJN

Reputation: 352

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

Upvotes: 0

Mr. Bhosale
Mr. Bhosale

Reputation: 3106

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  )

Upvotes: 2

Gurwinder Singh
Gurwinder Singh

Reputation: 39537

Use not in something like:

select tel_number, telnumber_id from alluser
where tel_number not in (select tel_number from blacklist);

Or may be NOT EXISTS:

select tel_number, telnumber_id from alluser t
where not exists (select tel_number from blacklist where tel_number = t.tel_number);

Upvotes: 0

Related Questions