SQLTeam.com | Weblogs | Forums

Multiple ordered aggregate functions in the same scope have mutually incompatible orderings

Hello

I have this query:
select t1.1, t1.2, t2.3, t2.4
from t1 join t2 on 8=9
where 6='a' and 7='b'

I want to string_agg all the columns in the selection by grouping by t1.1 so I did:
select t1.1,
string_agg(t1.2,','),
string_agg(t2.3,','),
string_agg(t2.4,',')
from t1 join t2 on 8=9
where 6='a' and 7='b'

but I get the error:
Multiple ordered aggregate functions in the same scope have mutually incompatible orderings.

Any idea?

Thanks!

Read the documentation aboit that function carefully especially the part about
WITHIN GROUP
order by section

ottps://docs.microsoft.com/en-us/sql/t-sql/functions/string-agg-transact-sql?view=sql-server-ver15

What that means
in plain easy to understand simple English

God when will those days come
.... Too much pain in the ****
I mean to understand. . error messages

It's not possible to do at least at this time
multiple things in the same query
Because each is different from the other

+++++++++++++
Ordering is different for the string agg

String agg 1
order different from
String agg 2
++++++++++++++
1,4,5
1,4,5

Versus

1,9,10
1,6, 7

1 Like