1
Good morning, I would like to know why my SQL query is not working, I am using SQL Server 2008 and my GROUP BY
is going wrong. I have checked and the table names are correct and are filled in correctly.
Code:
SELECT categoria, nome_categoria
FROM tabela_teste.dbo.teste
WHERE vigencia = '2016-04'
GROUP BY categoria
ORDER BY nome_categoria;
Error:
is invalid in the select list because it is not contained in either an Aggregate Function or the GROUP BY clause.
If you run the command select category from tabela_test.dbo.test Where vigencia = '2016-04' group by category order by name_category; works?
– Mateus
If it runs this way it still doesn’t work, the group by error continues. But if I remove the table name and the order by it works. However I need to use group by and order by for my research to work.
– fernando
Post the table structure. I answered a question here, see if it helps: http://answall.com/questions/131637/buscar-somente-o-menor-n%C3%Bamero-de-every-letter/131640#131640
– Marconi
Looking at some sites all use a group by followed by a group functions(sum, max...), in my case I do not need the group function. But as I said without the order by the command works, my table is filled correctly otherwise the command would not have worked, I came to think that group by works only with grouping functions.
– fernando
I looked at the link you sent me, grateful as I said above there you use the grouping function, try to put order by on your command and see if it works correctly.
– fernando