newbie question, why this solution got wrong answer?

  • 0

    Select Name as Customers from Customers
    where Name not in
    (Select Name
    From Customers join Orders
    on )

  • 1

    Theoretically your code should be working. However, Id in table 1 is the primary key with no duplicates, whereas Name is not. There is no guarantee that the event where two or more customers share the same name but different Id-s, would not happen.

    The sub query of your code is to find all customers who have ordered. Lets say James(a) with id of 3 and James (b) with id of 7. James (a) did order but James (b) didn't. The name list that your join clause returns will have James (a). When the outer structure kicks in, your code will not select all customers named James. That's why your code is not working. Hope it helps.

  • 0

    Understood, thank you very much for the detailed explanation!

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.