Home > front end >  mysql of searching where without any data by foreign key
mysql of searching where without any data by foreign key

Time:08-31

i have a problem of searching data .

A table

A_id name  
1    apple 
2    orange
3     sexy

B table

B_id A_id comment 
1      1         abcde

how can i get the a_id were without any comment in b table

i want the sql return

a_id name 
2 orange 
3 sexy

CodePudding user response:

SQLs NOT EXISTS operator is for that purpose:

select a_id, name
from A as AT
where not exists 
     (select *
      from B as BT
      where BT.a_id=AT.a_id)
  • Related