Combine Two Tables

easy hash map database join

Problem

Write a SQL query for a report that provides the firstName, lastName, city, and state of each person in Person. If the address of a personId is not present in Address, report NULL.

SQL: SELECT firstName, lastName, city, state FROM Person LEFT JOIN Address ON Person.personId = Address.personId;

Person[{1, "Wang", "Allen"}, {2, "Alice", "Bob"}]
Address[{1, 2, "NY", "NY"}]
Output[{"Allen","Wang","NY","NY"}, {"Bob","Alice",NULL,NULL}]

SELECT firstName, lastName, city, state
FROM Person
LEFT JOIN Address ON Person.personId = Address.personId;
Time: O(n + m) Space: O(m)