Solved

Group By, Aggrigate function ?

Posted on 2006-11-14
3
303 Views
Last Modified: 2012-06-21
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 ?
0
Comment
Question by:win32
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 17938449
select Site, count(*)
 from vToneAudiogramCurve
group by Side having count(*) = 2
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17938453
select * from vToneAudiogramCurve
where Side in ( select Site  from vToneAudiogramCurve group by Side having count(*) = 2 )
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17938464
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

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now