I have 2 tables and I want to combine these 2 tables into 1 (view) with 1 row per order. I want to check if an "id" from "order_address" table is linked with the "billing_address_id" from the "order" table. If thats the case this address is a billing-address and if its not linked is a shipping-address.
I tried a lot of things but I cant combine 2 rows with different values. See below. Is there some posibility to do this?
Order table:
| id | order_number | billing_address_id | order_date | order_amount |
|---|---|---|---|---|
| 1 | 1001 | 147 | 2023-04-14 | 81.88 |
| 2 | 1002 | 369 | 2023-04-18 | 29.99 |
Order_address table:
| id | order_id | first_name | last_name | street | zipcode | city |
|---|---|---|---|---|---|---|
| 147 | 1 | John | Doe | Washington Street 2 | 33101 | Miami |
| 369 | 2 | Dave | Dunkin | Power Street 33a | 10010 | New York |
| 465 | 2 | Marry | Dunkin | Power Street 14 | 14205 | Buffalo |
Actual output:
| order_number | first_name | last_name | street | zipcode | city |
|---|---|---|---|---|---|
| 1001 | Peter | Paper | Washington Street 2 | 33101 | Miami |
| 1002 | John | Dunkin | Power Street 33a | 10010 | New York |
| 1002 | Marry | Dunkin | Other Street 14 | 14205 | Buffalo |
Wanted Output:
| order_number | first_name | last_name | street | zipcode | city | ship_first_name | ship_last_name | ship_street | ship_zipcode | ship_city |
|---|---|---|---|---|---|---|---|---|---|---|
| 1001 | Peter | Paper | Washington Street 2 | 33101 | Miami | |||||
| 1002 | John | Dunkin | Power Street 33a | 10010 | New York | Marry | Dunkin | Other Street 14 | 14205 | Buffalo |