deanlee17
asked on
Solving error message 'An aggregate may not appear in the WHERE clause'
Hi guys,
As title says im getting that error message, I know why im getting it but what is the best work around? Ive tried a few but must be getting the syntax wrong.
SELECT PartNumber, Manufacture, COUNT(PartNumber) as TheCount
FROM CounterfeitParts
WHERE COUNT(PartNumber) > 1
Group BY PartNumber, Manufacture
Thanks,
Dean
As title says im getting that error message, I know why im getting it but what is the best work around? Ive tried a few but must be getting the syntax wrong.
SELECT PartNumber, Manufacture, COUNT(PartNumber) as TheCount
FROM CounterfeitParts
WHERE COUNT(PartNumber) > 1
Group BY PartNumber, Manufacture
Thanks,
Dean
ASKER
Incorrect syntax near the keyword 'Group'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
however, doing a count(PartNumber) here is usually better COUNT(*) instead ...
I know Guy (aka Scary Scar Puffy Shirt Dude) has already correctly answered your question, but if it helps I have an article out there on SQL Server Group By Solutions, and point #3 illustrates the HAVING clause. If the article helps you, please click the 'Yes' button at the bottom.
ASKER
Thanks Jim
Open in new window