Impala - Distinct Operator


Advertisements

The distinct operator in Impala is used to get the unique values by removing duplicates.

Syntax

Following is the syntax of the distinct operator.

select distinct columns… from table_name;

Example

Assume that we have a table named customers in Impala and its contents are as follows −

[quickstart.cloudera:21000] > select distinct id, name, age, salary from customers; 
Query: select distinct id, name, age, salary from customers

Here you can observe the salary of the customers Ramesh and Chaitali entered twice and using the distinct operator, we can select the unique values as shown below.

[quickstart.cloudera:21000] > select distinct name, age, address from customers;

On executing, the above query gives the following output.

Query: select distinct id, name from customers
+----------+-----+-----------+ 
| name     | age | address   | 
+----------+-----+-----------+ 
| Ramesh   | 32  | Ahmedabad |
| Khilan   | 25  | Delhi     | 
| kaushik  | 23  | Kota      | 
| Chaitali | 25  | Mumbai    |
| Hardik   | 27  | Bhopal    |
| Komal    | 22  | MP        | 
+----------+-----+-----------+
Fetched 9 row(s) in 1.46s
Advertisements