mysql of searching where without any data by foreign key


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


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)

Answered By – tinazmu

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published