1

When using node-mysql, this select SELECT shop.shopId, shop.name, address.address FROM shop INNER JOIN address ON shop.shopId = address.shopId returns a json like that:

[{
     "shopId":1,
     "name":"Lorem",
     "street":"Street XXXXX"
},{
     "shopId":1,
     "name":"Lorem",
     "street":"Street YYYYY"
},{
     "shopId":2,
     "name":"Ipsum",
     "street":"Street ZZZZZ"
}]

But what I need is something like this

[{
     "shopId":1,
     "name":"Lorem",
     "street":[{"Street XXXXX"},{"Street YYYYY"}]
},{
     "shopId":2,
     "name":"Ipsum",
     "street":"Street ZZZZZ"
}]

How could i do that using node-mysql? Knex or sequelize can do it?

1 Answer 1

2

Try adding GROUP BY shopId . I guess changing the Sql string can give you desired results.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.