Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:07:18+00:00 2026-06-04T13:07:18+00:00

I have some experience with MySQL and recently I have to do some work

  • 0

I have some experience with MySQL and recently I have to do some work on HIVE instead.

The basic structure of the queries is quite similar between the two, but the GROUP BY in HIVE seems to work a bit differently… Thus I cannot achieve what I could previously achieve in MySQL using GROUP BY.

Following is my question, so say I have a table with column A, B, C, and I want to select the rows with max. B column values grouping by column A. I will do:

SELECT A, max(B) FROM myTable GROUP BY A

The above code would work in HIVE with no problem. But what if I also want to see the value in column C which is in the same row of the row with max. B value? In MySQL I can just do:

SELECT A, max(B), C FROM myTable GROUP BY A

But in HIVE I can’t do this. It complains that C is not in the GROUP BY keys, but if I add C into GROUP BY, the result is totally not what I want.

So what is the way to select such desired result in HIVE? Some say using collect_set on column C can solve the problem, but I have no idea how the collect_set is ordered and thus don’t know which element to return…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:07:19+00:00Added an answer on June 4, 2026 at 1:07 pm

    Okay I figured this out… The following would do the trick:

    SELECT A, maxB, C FROM myTable JOIN
    (SELECT A, max(B) as maxB FROM myTable GROUP BY A) temp
    ON myTable.A = temp.A AND myTable.B = temp.maxB
    

    It turns out that I have to write much more code in HIVE to get the same result as I would get with just one line in MySQL… 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to Microsoft SQL Server. I have some experience with MySQL, and
I have some experience in ASP.Net and can work my way around it without
I have recently decided to switch all my current plain mysql queries performed with
i have some experience with MySQL but none with SQL Server, i have a
I'm trying to optimize a SQL Server. I have some experience with Mysql and
I have some experience using parallel extensions in .Net development, but I was looking
I have some experience writing web applications in Java for class projects. My first
I have some experience with Java , C , databases , networking etc..But anything
Hi I have some experience with programming but I'm not very good with pointers.
I'm doing some homework and while I have some experience with SML, Haskell has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.