Impala HAVING Clause with Syntax & Restrictions

Boost your career with Free Big Data Courses!!

In our previous, tutorial we learn Impala LIMIT Clause. Here, we are going to learn the Impala Having Clause. This is used to specify conditions that filter which group results appear in the final results in Impala. Moreover, we will see the introduction, syntax, type, and example, to understand it well.

So, let’s discuss Impala Having Clause.

Impala HAVING Clause

Basically, Impala HAVING Clause examines the results of aggregation functions rather than testing each individual table row then performs a filter operation on a SELECT query.

Hence, we can say we use it in conjunction with functions always. Such as COUNT(), SUM(), AVG(), MIN(), or MAX(). Also, with the GROUP BY clause,  typically.

In other words, it enables you to specify conditions that filter which group results appear in the final results in Impala.

However, we use this clause along with the Group By Clause. So, that places conditions on groups created by the GROUP BY Clause.

a. The syntax of HAVING Clause

So, the syntax for using Impala HAVING Clause is-

select * from table_name ORDER BY col_name [ASC|DESC] [NULLS FIRST|NULLS LAST]

b. Restrictions in Impala Having Clause 

There is one restriction while using  Impala HAVING Clause is that here filter expression cannot include a scalar subquery.

Example of Having Clause in Impala

For Example,
Let us suppose we have a table named Employees in the database my_db. Its contents are −

[quickstart.cloudera:21000] > select * from Employees;

Query: select * from Employees

idnameageaddresssalary
1shubham32delhi20000
2monika25mumbai15000
3kajal27alirajpur40000
4revti25indore35000
5shreyash23pune30000
6mehul22hyderabad32000
7 Vaishnavi25Goa23000
8Rishabh22chennai31000
9Pulkit23Gandhi nagar28000

Fetched 9 row(s) in 0.51s

So, now let’s see an example of using Having clause in Impala −

[quickstart.cloudera:21000] > select max(salary) from Employees group by age having max(salary) > 20000;

This query displays those salaries, which are greater than 20000, but initially, it groups the table by age and selects the maximum salaries of each group.
20000

max(salary)
30000
35000
40000
32000

Fetched 4 row(s) in 1.30s
So, this was all about Impala Having Clause. Hope you like our explanation.

Conclusion

Hence, we have seen the whole concept of Impala HAVING Clause. Moreover, we discussed syntax and example of Having Clause in Impala. Still, if any doubt occurs, feel free to ask in the comment section.

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *