Loading...
Loading...
Loading...
Person table: PersonId is PK, has firstName, lastName Address table: AddressId is PK, has PersonId FK, city, state PersonId in Address need not exist in Person
Given two tables Person and Address, write a SQL query to report the first name, last name, city, and state of each person.
If the address of a personId is not present in the Address table, report null for city and state.
Return the result table in any order.
| Column | Type |
|---|---|
| personId | int |
| lastName | varchar |
| firstName | varchar |
| Column | Type |
|---|---|
| addressId | int |
| personId | int |
| city | varchar |
| state | varchar |
Person to Address on personId. INNER JOIN would drop persons without an address.SELECT p.firstName, p.lastName, a.city, a.state
FROM Person p
LEFT JOIN Address a ON p.personId = a.personId;