Impala - Select Statement


Advertisements


Impala SELECT statement is used to fetch the data from one or more tables in a database. This query returns data in the form of tables.

Syntax

Following is the syntax of the Impala select statement.

SELECT column1, column2, columnN from table_name;

Here, column1, column2...are the fields of a table whose values you want to fetch. If you want to fetch all the fields available in the field, then you can use the following syntax −

SELECT * FROM table_name;

Example

Assume we have a table named customers in Impala, with the following data −

ID    NAME       AGE    ADDRESS      SALARY
---   -------    ---    ----------   -------
1     Ramesh     32     Ahmedabad    20000
2     Khilan     25     Delhi        15000
3     Hardik     27     Bhopal       40000
4     Chaitali   25     Mumbai       35000
5     kaushik    23     Kota         30000
6     Komal      22     Mp           32000

You can fetch the id, name, and age of all the records of the customers table using select statement as shown below −

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

On executing the above query, Impala fetches id, name, age of all the records from the specified table and displays them as shown below.

Query: select id,name,age from customers

+----+----------+-----+
| id | name     | age |
| 1  | Ramesh   | 32  |
| 2  | Khilan   | 25  |
| 3  | Hardik   | 27  |
| 4  | Chaitali | 25  |
| 5  | kaushik  | 23  |
| 6  | Komal    | 22  |
+----+----------+-----+

Fetched 6 row(s) in 0.66s

You can also fetch all the records from the customers table using the select query as shown below.

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

On executing the above query, Impala fetches and displays all the records from the specified table as shown below.

+----+----------+-----+-----------+--------+
| id | name     | age | address   | salary |
+----+----------+-----+-----------+--------+
| 1  | Ramesh   | 32  | Ahmedabad | 20000  |
| 2  | Khilan   | 25  | Delhi     | 15000  |
| 3  | Hardik   | 27  | Bhopal    | 40000  |
| 4  | Chaitali | 25  | Mumbai    | 35000  |
| 5  | kaushik  | 23  | Kota      | 30000  |
| 6  | Komal    | 22  | MP        | 32000  |
+----+----------+-----+-----------+--------+

Fetched 6 row(s) in 0.66s

Fetching the Records using Hue

Open Impala Query editor and type the select Statement in it. And click on the execute button as shown in the following screenshot.

Fetching Records

After executing the query, if you scroll down and select the Results tab, you can see the list of the records of the specified table as shown below.

Fetching Records Result

Advertisements
E-Books Store