Consider the table as below –
Table A
Parent_Id | Child_Id | is_active |
---|---|---|
P1 | C1 | Y |
P1 | C2 | N |
P2 | C3 | N |
Need the SQL query to identify the parent_id which has all child_id with ‘N’. In the above table the output should be
Parent_Id
P2
Advertisement
Answer
SELECT Parent_Id FROM tableA GROUP BY Parent_Id HAVING !SUM(is_active = 'Y')
or
HAVING MAX(is_active) = 'N'