I have to create a GET type of API and I have to connect two tables.
For example, I have the following tables:
Table 1:
- customer_id: {001}
- first_name: {f_name}
- last_name: {l:name}
Table 2:
- customer_id: {001} {001}
- street: {A street} {B street}
- zip_code: {1234} {1234}
- city: {xxxx} {xxxx}
- country: {xx} {xx}
If I connect the two tables I get the following result:
{
"customer_id": 001,
"first_name": "f_name",
"last_name": "l_name",
"street": "A street",
"zip_code": "1234",
"city": "xxxx",
"country": xx
}
{
"customer_id": 001,
"first_name": "f_name",
"last_name": "l_name",
"street": "B street",
"zip_code": "1234",
"city": "xxxx",
"country": xx
}
This is beacuse the table2 has two rows with the customer_id:"001".
But I want this kind of result:
{
"customer_id": 001,
"first_name": "f_name",
"last_name": "l_name",
"address": [
{
"street": "A steet",
"zip_code": "1234",
"city": "xxxx",
"country": xx
},
{
"street": "B street",
"zip_code": "1234",
"city": "xxxx",
"country": xx
}
]
}
It seems like a simple query won't work here. Has anybody ideal how should I create this GET type of API?

