0
I have a page in PHP where I have to return data from two tables that are in a database SQL Server.
One of the banks is registered sellers and the other is of the categories where they are registered. I need to make a comparison and check how many sellers are registered by category.
I made the following consultation:
SELECT Vendedor.IdCanal, Count(Vendedor.IdCanal) total, CanalVenda.Nome FROM Vendedor INNER JOIN CanalVenda On Vendedor.IdCanal=CanalVenda.Id GROUP BY Vendedor.IdCanal
The problem happens that this query does not return me the field where has the name category. When I add it to the query, it returns the following error:
[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Column 'CanalVenda.Nome' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
How to correctly return field results Nome?
Thanks @Ginaldo-Rigo, it worked perfectly. That’s right, I needed to put the
CanalVenda.Nomeat Group By. Thank you very much.– Mauro Alves