Thursday, September 26, 2013

SQL server select A.*, count(b) group by

SQL server select A.*, count(b) group by

I want to run a query on sql server to select all the elements in a table
(tableA) with an aggregate from another table
select a.*, count(b.number) from tableA a
inner join tableB b on a.id = b.a_id
group by a.id;
This gives the following error :
Error: Column 'a.id' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.
SQLState: S1000
ErrorCode: 8120
What is the right query to get what i want?

No comments:

Post a Comment