I immediately apologize for my English to you. The fact is that I need to write a get request for my application with recipes. I want to make the request look like this:
{
"items": [
{
"id_recipe": 1,
"ingredients": [
{
"name_ingredient": "Ingredient1",
"counts": 30,
"name_unit": "unit1"
},
{
"name_ingredient": "Ingredient2 ",
"counts": 1,
"name_unit": "unit2 "
},
{
"name_ingredient": "Ingredient3",
"counts": 2,
"name_unit": "unit1 "
}
]
},
{
"id_recipe": 2,
"ingredients": [
{
"name_ingredient": "Ingredient2",
"counts": 1,
"name_unit": "unit3 "
},
{
"name_ingredient": "Ingredient1",
"counts": 400,
"name_unit": "unit4"
}
]
}
]
}
But it looks like this
{
"items": [
{
"id_recipe": 1,
"name_ingredient": "Ingredient1",
"counts": 30,
"name_unit": "unit1"
},
{
"id_recipe": 1,
"name_ingredient": "Ingredient2 ",
"counts": 1,
"name_unit": "unit2 "
},
{
"id_recipe": 1,
"name_ingredient": "Ingredient3",
"counts": 2,
"name_unit": "unit1 "
},
{
"id_recipe": 2,
"name_ingredient": "Ingredient2",
"counts": 1,
"name_unit": "unit3 "
},
{
"id_recipe": 2,
"name_ingredient": "Ingredient1",
"counts": 400,
"name_unit": "unit4"
}
]
}
That is, it is necessary to somehow combine elements with the same id_recept into an array. But I do not know how! Here's the code I'm using now:
SELECT PRODUCTS.ID_RECIPE, INGREDIENTS.NAME_INGREDIENT, PRODUCTS.COUNTS, UNITS_OF_MEASUREMENT.NAME_UNIT
FROM PRODUCTS, INGREDIENTS, UNITS_OF_MEASUREMENT
WHERE PRODUCTS.ID_INGREDIENT = INGREDIENTS.ID_INGREDIENT
AND PRODUCTS.ID_MEASUREMENT = UNITS_OF_MEASUREMENT.ID_MEASUREMENT
ORDER BY ID_RECIPE
This is how the table data looks like: table ingredients
I use oracle. I will be glad if you can help!