There are two tables - one with the names of the girls and the guys that they like and a table with the names of the guys and girls that they like. How to write a request to display the names of all the girls who do not like any guy?

Table view

  • 2
    select distinct name from girls where name not in (select likes from boys) ? - teran
  • @teran, the answers to the answers? - Qwertiy

1 answer 1

Using left join:

 SELECT Girls.* FROM Girls LEFT JOIN Boys ON Girls.Name = Boys.Likes WHERE Boys.Name IS NULL 

Using EXISTS:

 SELECT * FROM Girls g WHERE NOT EXISTS(SELECT Name FROM Boys b WHERE g.Name = b.Likes)