I have the following query:
SELECT
COUNT(IDPROVEEDORES),
IDPROVEEDOR
FROM PROVEEDORES
WHERE COUNT(IDPROVEEDORES) > 1
But I get the following error:
Incorrect syntax near the keyword 'where'.
I have the following query:
SELECT
COUNT(IDPROVEEDORES),
IDPROVEEDOR
FROM PROVEEDORES
WHERE COUNT(IDPROVEEDORES) > 1
But I get the following error:
Incorrect syntax near the keyword 'where'.
When the filtering condition you want to do on the result of the aggregation function, then you must use the statement HAVING
, not a WHERE
(this is because the WHERE
is used to filter the data with which the aggregation function is calculated).
In your case, you should use:
SELECT COUNT(IDPROVEEDORES), IDPROVEEDOR
FROM PROVEEDORES
GROUP BY IDPROVEEDOR
HAVING COUNT(IDPROVEEDORES) > 1
;