What is the difference between foreach and foreachPartition in Spark?
October 4, 2021How to calculate the difference between 2 dates in Hive?
October 11, 2021Simple problem with a simple solution.
Solution
Order the records first and then apply the LIMIT clause to limit the number of records.
SELECT * FROM employee ORDER BY salary DESC LIMIT 20
Keep in mind ORDER BY does a global ordering and it is an expensive operation.
Check out this post on differences between ORDER BY, SORT BY in Hive.