Having simple database structure
PERSON_ID FIRST_NAME LAST_NAME
1 John Doe
2 John Doe
3 Peter Jackson
need to construct single row output with JSON ARRAY structure containing unique data filtered by first_name,last_name criteria.
Expected outcome:
[{
"firstname": "John",
"lastname": "Doe"
},
{
"firstname": "Peter",
"lastname": "Jackson"
}]
Using group by on array level results in two rows
SELECT json_array(
json_object( key 'firstname' VALUE t.first_name,
key 'lastname' VALUE t.last_name)
) RESPONSEJSON
FROM TESTDATA t
GROUP BY t.first_name, t.last_name
RESPONSEJSON
1 [{"firstname":"Peter","lastname":"Jackson"}]
2 [{"firstname":"John","lastname":"Doe"}]