Skip to content
Advertisement

Is such a result possible with a query from an SQL database?

I want to fire a query to get such a result:

Tables Schema

I guess it’s not possible like that? I don’t have any experience with text-based databases, but I can well imagine that this can be achieved with a MongoDB. Because ultimately I want to have a js object at the end of the day.

Advertisement

Answer

Here’s an example but I have not tested it:

Note that I had to assume the ModelsTable also contains a column for brand_id, otherwise there is nothing to use in the join condition.

Read documentation for JSON_OBJECT() and JSON_ARRAYAGG() for more information about how these functions work.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement