SQL Division using 'not exists' in mysql

后端 未结 1 1051
长情又很酷
长情又很酷 2021-01-07 03:04

I have the following table:


\'committee\' table

commname    profname
========================
commA       bill
commA       jack
commA       piper
commB       bi         


        
相关标签:
1条回答
  • 2021-01-07 03:48

    Your innermost select isn't using anything from itself in its where clause, so it's always finding something for piper. Try

    select distinct b.profname from committee b
    where not exists (
        select commname from committee a
        where a.profname = 'piper' and not exists  (
            select commname from committee c
            where c.profname=b.profname and c.commname=a.commname
        )
    );
    
    0 讨论(0)
提交回复
热议问题