Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive: Select rows with max value from a column

I want to select all rows for which the timestamp column has the maximum value. The data looks like this:

A      B      timestamp
john   smith   2018
bob    dylan   2018
adam   levine  2017
bob    dylan   2017

The result should be:

A      B      timestamp
john   smith   2018
bob    dylan   2018

With Impala, the following SQL Query works: SELECT * FROM table WHERE timestamp=(SELECT Max(timestamp) from table)

But with Hive, the SQL Query doesn't.

like image 941
Mehmet Ates Avatar asked May 19 '26 13:05

Mehmet Ates


1 Answers

Please always include the error message.

Try with

SELECT * FROM table WHERE timestamp IN (SELECT Max(timestamp) from table)
like image 57
Harold Avatar answered May 22 '26 03:05

Harold



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!