Group By, Aggrigate function ?

Hi, I have written the SQL:

select * from vToneAudiogramCurve
group by Side having count(*) = 2

Then I get the error:
Column 'vToneAudiogramCurve.Client_ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

The reason I wan to groop it, and use the having count(') = 2 is that I only want to see results that is in 2 times. How can I get this to work ?
win32Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
select Site, count(*)
 from vToneAudiogramCurve
group by Side having count(*) = 2
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
select * from vToneAudiogramCurve
where Side in ( select Site  from vToneAudiogramCurve group by Side having count(*) = 2 )
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
you need to specify all the columns except those used for the aggregate functions, for eg, if you have columns Col1, col2 ...Coln
then

SELECT Col1,Col2
FROM urTable
GROUP BY Col1,Col2
Having Count(*) >1
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.