Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select top 2 rows in Hive

I'm trying to retrieve top 2 tables from my employee list based on salary in hive (version 0.11). Since it doesn't support TOP function, is there any alternatives? Or do we have define a UDF?

like image 321
Holmes Avatar asked May 25 '15 15:05

Holmes


People also ask

Can we use top in Hive?

Yes, here you can use LIMIT .

How do I SELECT specific rows in Hive?

hive SELECT Statement Select Specific Rows You can use the keyword RLIKE to use Java regular expressions. The following query will return rows which column name contains the words "smith" or "son". You can apply functions to the returned data. The following sentence will return all name in upper case.

How do I limit rows in Hive?

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants. The first argument specifies the offset of the first row to return (as of Hive 2.0.

Is there a dual table in Hive?

In Hive, there is no system table named Dual. However you can directly created table name Dual.


1 Answers

Yes, here you can use LIMIT.

You can try it by the below query:

SELECT * FROM employee_list SORT BY salary DESC LIMIT 2 
like image 92
Akshay Shrivastava Avatar answered Sep 30 '22 09:09

Akshay Shrivastava