IN SQL, HAVING CLAUSE

Status
Not open for further replies.

Soham1087

Banned
Joined
May 31, 2022
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
India
Activity points
185
I'm attempting to figure out why certain DBMS systems allow the following but others don't. Assume table X contains the following attributes: name, id, and data.
Code:
SELECT id, count(*) as count
FROM TABLE X
GROUP BY id
HAVING count > X.data
It is forbidden in most databases to utilize a non-grouping or non-aggregate field in a HAVING clause conditional statement. Some systems appear to permit the same. Could you explain why they would have permitted the HAVING condition to utilize a property that may not have a unique value throughout the group? I found some useful info but need further explanation. Database documentation for DB2, PostgreSQL, and MySQL was consulted.
Code:
SELECT id, count(*) as count
FROM TABLE X
GROUP BY id
HAVING count > X.data
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…