HEXAQ : A friendly question - answer site for IT professionals

SQL Server - An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.


0

I have a table having products. created with structure

CREATE TABLE [Products] (

    [ProductId]    INT,

    [ProductName]     VARCHAR(80),

    [ProductMake]      VARCHAR(255)

)

To find out duplicate product names I have written following query

SELECT [ProductName], [ProductMake], COUNT(*)

FROM [Products]

WHERE COUNT(*) > 1

GROUP BY [ProductName], [ProductMake]

I am getting this error when I execute my query.

Server: Msg 147, Level 15, State 1, Line 3  

An aggregate may not appear in the WHERE clause unless it is in a 
subquery contained in a HAVING clause or a select list, and the column 
being aggregated is an outer reference.

Any guess whats wrong with my query?

Â
asked
 


≡ Total 0 Answer

Enter your reply here
Answer Preview: