Having table msg
like this:
id, msgNo, frag
1, 1, AAA
2, 1, BBB
3, 1, CCC
4, 2, Hello
I can get such result:
msgNo, mesg
1, AAABBBCCC
2, Hello
using:
SELECT msgNo, STRING_AGG(CONVERT(NVARCHAR(MAX), frag), '') AS mesg
FROM msg
GROUP BY msgNo
Question is, how can I get this?:
msgNo, mesg
1, CCCBBBAAA
2, Hello
meaning, that I concatenate strings in descending id
order.
If someone can give me an explanation for both MySQL and Sql Server that would be awesome.