ORDER BY elements should appear in the selection list if a SELECT DISTINCT error is selected

I need to specify a field in a certain way, but sort it differently. Here is the request. How to get around this?

SELECT DISTINCT tsgroup FROM master ORDER BY RIGHT(RTRIM(tsgroup), 3), LEFT(rtrim(tsgroup), 3) 
+4
source share
2 answers

Instead of GROUP BY you can use

 SELECT tsgroup FROM master GROUP BY tsgroup ORDER BY RIGHT(RTRIM(tsgroup), 3), LEFT(RTRIM(tsgroup), 3) 
+9
source

how to hack:

 select grp from ( select distinct tsgroup as grp from master ) order by RIGHT(RTRIM(grp), 3) , left(rtrim(grp), 3) 
0
source

All Articles