This is my databasedesign with a many-to-many relation
table Tournament
TournamentId int
name varchar(45)
table User
UserId int
name varchar(45)
table Tournament_Users
Tournament_Id int
User_Id int
I am attempting to return all tournaments with a list of the tournament's users in a JSON format. I'm not sure if this is possible to do in the query or it's a javascript job? I tried to follow this Returning child rows formatted as JSON in SQL Server queries but I drowned in the example.
This is my current query
SELECT t.TournamentId, t.Name as tourName, u.UserId, u.Name as userName
FROM Tournament_Users tu
LEFT JOIN Tournaments t ON tu.Tournament_Id = t.TournamentId
LEFT JOIN Users u ON u.UserId = tu.User_Id
So as a json result this looks like this:
Which seems pretty difficult for a client to work with. How can I convert it into a format like this?
SQLFIDDLE: http://sqlfiddle.com/#!9/9bc2ebf/3



SHOW CREATE TABLE table) and example data for all table involved on sqlfiddle.com.. Then we can help you..