Combine Two Tables
✅ IntuitionWe are given two tables: Person and Address. Each person may or may not have an address. We want to return each person's firstName, lastName, city, a


---

### ✅ **Intuition**
<!-- Describe your first thoughts on how to solve this problem. -->
We are given two tables: `Person` and `Address`. Each person **may or may not** have an address. We want to return each person's `firstName`, `lastName`, `city`, and `state`. If a person does not have an address, we still want to include them (with NULL values for `city` and `state`).

---

### ✅ **Approach**
<!-- Describe your approach to solving the problem. -->
- Use a `LEFT JOIN` to join the `Person` table with the `Address` table using the common column `personId`.
- A `LEFT JOIN` ensures all records from the `Person` table appear, even if there is no matching entry in the `Address` table.
- Select the required fields from both tables: `firstName`, `lastName`, `city`, and `state`.

---

### ✅ **Complexity**
- **Time complexity:**  
  $$O(n)$$  
  Where **n** is the number of rows in the `Person` table. The join operation depends on indexing and may vary in practical scenarios.

- **Space complexity:**  
  $$O(1)$$  
  No extra space is used beyond the result set.

---

### ✅ **Code**
```mysql
SELECT 
    p.firstName,
    p.lastName,
    a.city,
    a.state
FROM 
    Person p
LEFT JOIN 
    Address a
ON 
    p.personId = a.personId;
```

---

['MySQL']