The table structure is as follows:
NOTE: The names used are for illustrative purposes only.
Table T1 – col1 INT, col2 CHAR, col3 VARCHAR
Table T2 – col1 INT, col2 VARCHAR col3 CHAR
Table T3 – col1 INT – col1 from Table 2 col2 INT – col2 from Table T col3 INT
SELECT tt1.col2, COUNT(tt1.col1) FROM T1 tt1, T2 tt2, T3 tt3 WHERE tt2.col1 = tt3.col1 AND
tt3.col2 = tt1.col1 GROUP BY tt1.col1, tt1.col2 HAVING EVERY (tt2.col3 = 'something');
This shows an error that matches the title of the question; However, no error is reported if I remove the HAVING clause.
Is the query syntactically correct?
It doesn’t appear that you need a HAVING clause. You use a HAVING clause when you need to filter results after your GROUP BY has been executed. For example, if you wanted only the records with a count(tt1.col1) greater than 10, you would use a HAVING clause. (HAVING count(tt1.col1) > 10)