Select parent if all children meet criteria

前端 未结 3 1962
小蘑菇
小蘑菇 2021-02-14 14:29

I have tables set up like so:

Parent
------
id, ...

Child
-----
id, parent_id, x, y

I want to find the Parents, or the distinct parent_id(s),

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-14 15:14

    This is what you need?

      select id from parent where id not in(
        select parent_id from chile 
        where x<>y
        group by parent_id)
    

提交回复
热议问题