0

I was solving a problem in Hackerrank, and I tried the following snippet for my solution:

SELECT N AS VALUE,
CASE
    WHEN P IS NULL THEN "Root"
    WHEN N NOT IN (SELECT P FROM BST) THEN "Leaf"
    ELSE "Inner"
END
AS TYPE FROM BST ORDER BY N ASC;

But this proved to be not correct. Then I inverted the second case and the last, then it worked out. It looks as follows:

SELECT N AS VALUE,
CASE
    WHEN P IS NULL THEN "Root"
    WHEN N IN (SELECT P FROM BST) THEN "Inner"
    ELSE "Leaf"
END
AS TYPE FROM BST ORDER BY N ASC;

Then I checked to see whether it is supported or not.

MySQL NOT IN

According to the link above, it seems it is a supported operation. So what's wrong with the first snippet?

Hackerrank Problem

ibrahim koz
  • 222
  • 2
  • 9

0 Answers0