szpic
szpic

Reputation: 4498

Column is not contained in either an aggregate function or the GROUP BY clause

I have to tables: DeviceInstace and Device

They are connected with Foreign Key on DeviceInstance.DeviceId=Device.Id

I have SQL query:

select d.CatalogNo,d.Manufacturer,d.Name, sum(quantity) 
from DeviceInstance di 
full join Device d 
on d.Id=di.DeviceId 
group by di.DeviceId

with which I need to make little summary that consist of:

But I'm facing some Grouping by issuses.

All I try refuse me error like this one:

Column 'Device.CatalogNo' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

I know I can group by CatalogNo but then ten sum of quantity will return wrong numbers.

Can anyone suggest me how to repair it?

Upvotes: 3

Views: 19517

Answers (2)

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28423

You need to Add d.CatalogNo,d.Manufacturer in Group By Clause

Try this

select d.CatalogNo,d.Manufacturer,d.Name, sum(quantity) 
from DeviceInstance di 
full join Device d 
on d.Id=di.DeviceId 
group by d.Name, d.CatalogNo,d.Manufacturer

Upvotes: 1

bjnr
bjnr

Reputation: 3437

Just modify GROUP BY clause:

group by d.DeviceId, d.CatalogNo,d.Manufacturer,d.Name

Upvotes: 3

Related Questions