I have 2 tables.
Table 1 (P_Data) Table 2 (Address)
| Data_Id | First_Name | Last_Name | | ID | Data_Id | Address_Type | address_data|
|---------|-------------|-----------| |----|----------|--------------|-------------|
| 1 | John | Page | | 1 | 1 | Residential | address1 |
| 2 | Bob | Builder | | 2 | 1 | Bill_To | address2 |
| 3 | 2 | Residential | address3 |
| 4 | 2 | Bill_To | address4 |
I want an output with only 2 fields but it must contain all the addresses (either 1 or many or none) for each id belonging to P_Data table.
Maybe like
| Data_Id | First_Name | Last_Name | Address_Type | address_Data |
|---------|-------------|-----------|---------------|--------------|
| 1 | John | Page | Residential | address1 |
| | | | Bill_To | address2 |
| 2 | Bob | Builder | Residential | address3 |
| | | | Bill_To | address4 |
Is it even possible? Or something which won't repeat the Data_Id field but will also give all the Address fields.
Note: The address fields can be none to 10 for one Data_Id. Looking for a generalised query.
EDIT: I tried this
SELECT pd.Data_Id, pd.First_Name, pd.Last_Name, a.Address_Type, a.address_data
from P_Data as pd
JOIN Address as a ON pd.Data_Id = a.Data_Id
got this as output
| Data_Id | First_Name | Last_Name | Address_Type | address_Data |
|---------|-------------|-----------|---------------|--------------|
| 1 | John | Page | Residential | address1 |
| 1 | John | Page | Bill_To | address2 |
| 2 | Bob | Builder | Residential | address3 |
| 2 | Bob | Builder | Bill_To | address4 |