Error: 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.


Error: 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.

Description: This error occur when we try to use aggregate functions with WHERE clause. Because, WHERE clause filters ungrouped elements or we can say WHERE clause can filter only table row-by-row or individual records.

Solution: By using HAVING clause instead of WHERE clause, which specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement which should return only those rows where aggregate values meet the specified conditions. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s