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 6319729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:51:21+00:00 2026-05-24T15:51:21+00:00

Consider following table. I’m trying to write a query to display – Max values

  • 0

Consider following table.


enter image description here


I’m trying to write a query to display – Max values for all the parts per category. Also display the date when the value was max.

So i tried this –

select Part_id, Category, max(Value), Time_Captured
from data_table
where category = 'Temperature'
group by Part_id, Category

First of all, mysql didn’t throw an error for not having Time_Captured in group by.
Not sure if its a problem with mysql or my mysql.

So I assume it should return –

1   Temperature 50  11-08-2011 08:00
2   Temperature 70  11-08-2011 09:00

But its returning me the time captured from the first record of the data set i.e. 11-08-2011 07:00

Not sure where I’m going wrong. Any thoughts?

(Note: I’m running this inside a VM. Just in case if it changes anything)

  • 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-05-24T15:51:22+00:00Added an answer on May 24, 2026 at 3:51 pm

    You need to join to the results of a query that finds the max(value), like this:

    select dt.Part_id, dt.Category, dt.Value, dt.Time_Captured
    from data_table dt
    join (select Part_id, Category, max(Value) as Value
              from data_table group by 1, 2) x 
        on x.Part_id = dt.Part_id and x.Category = dt.Category
    where dt.category = 'Temperature';
    

    Note that this will return multiple rows if there are multiple rows with the same max value.

    If you want to limit this to one row even though there are multiple matches for max(value), select the max(Time_Captured) (or min(Time_Captured) if you prefer), like this:

    select dt.Part_id, dt.Category, dt.Value, max(dt.Time_Captured) as Time_Captured
    from data_table dt
    join (select Part_id, Category, max(Value) as Value
              from data_table group by 1, 2) x 
        on x.Part_id = dt.Part_id and x.Category = dt.Category
    where dt.category = 'Temperature'
    group by 1, 2, 3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.