Select top 2 rows in Hive

Holmes picture Holmes · May 25, 2015 · Viewed 106.1k times · Source

I'm a noobie here. 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?

Answer

Akshay Shrivastava picture Akshay Shrivastava · May 25, 2015

Yes, here you can use LIMIT.

You can try it by the below query:

SELECT * FROM employee_list SORT BY salary DESC LIMIT 2