I have a page in PHP where I have to return data from two tables that are in a SQL Server database.
One of the banks is from registered sellers and the other is from 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 query:
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 is that this query does not return the field where the name of the Category. When I add it in the search, 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 properly return results from field Nome
?