Skip to content
Advertisement

How to get JSON string for each distinct field

I have two tables DbContours:

and SimpleLines:

One row in DbContours has multiple corresponding rows in SimpleLines via field ContourId in SimpleLines table. I managed to write query to get all rows in SimpleLines that have ContourId from table DbContours:

I Want to get json string of all SimpleLines for each distinct ContourID (resulting Select must contain multiple rows of json string based on distinct ContourId) . How to do it?

I think it must be something like this, but for each ContourId and not particular:

Each resulting JSON string should look like this:

Advertisement

Answer

If you want …to get json string of all SimpleLines for each distinct ContourID… and the …resulting Select must contain multiple rows of json string based on distinct ContourId…, a possible approach is to generate a JSON output for each ContourId:

Tables:

Statement:

Result:

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