Skip to content

Latest commit

 

History

History
32 lines (31 loc) · 701 Bytes

608. Tree Node.md

File metadata and controls

32 lines (31 loc) · 701 Bytes

608. Tree Node

Question Link

Why Can't Use 'not in' While 'in' Is Accepted

When there is a null in a column, we can't use not in in a clause. We can only use in.

Wrong Code - Use not in

# Write your MySQL query statement below
select id,
case
when p_id is null then 'Root'
when id not in (
  select p_id from Tree
) then 'Leaf'
else 'Inner'
end type
from Tree

All results supposed to be Leaf are Inner now.

Right Code - Use in

# Write your MySQL query statement below
select id,
case
when p_id is null then 'Root'
when id in (
  select p_id from Tree
) then 'Inner'
else 'Leaf'
end type
from Tree