A GROUP-BY expression must contain at least one column that is not an external reference

I have this query:

SELECT SolutionName -- Solution_NAM from Table_View Group By 1 

where Table_View is, of course, a view. I get an error message:

Each GROUP BY expression must contain at least one column that is not an external reference.

Can you help me solve this? It is inside Ms SQL Server 2008

+4
source share
2 answers

you cannot give a group 1

to try

 SELECT SolutionName -- Solution_NAM from Table_View Group By SolutionName 
+3
source

Martin's statement about GROUP BY is true, although you> can <definitely use the column number instead of the column name in ORDER BY in various versions of SQL (I think TSQL, which is an ISO standard in most basic SQL syntaxes).

But it’s good practice not to use columnar ordinals in ORDER BY statements, even if they really work. What for? If the query is part of a stored process and the table schema is changed by adding a column to the original table (or view), there is no guarantee that the original column ordering will be supported by the change. This would mean that you can order an unintentional and meaningless column, which then breaks your application.

It is much better to use column names rather than ordinals every time (although, like count (*), do not get stuck on it if it asks for special requests for your own use that will never see the light of day in production).

0
source

Source: https://habr.com/ru/post/1437739/


All Articles