My Solution And Question With Union


  • 1
    W

    Just come up with this idea to do it. Does anyone have any advises to make it better?
    By the way, besides using join, does anybody have any idea to do it by using CASE?

    SELECT per.FirstName, per.LastName, addr.City, addr.State
    FROM Person per, Address addr
    WHERE per.PersonId = addr.PersonId
    UNION
    SELECT per.FirstName, per.LastName, NULL as City, NULL as State
    FROM Person per
    WHERE per.PersonId NOT IN (SELECT PersonId from Address);
    

Log in to reply
 

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