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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:01:20+00:00 2026-05-31T04:01:20+00:00

I am using select field1, max(updated_date) from mytable . I get the correct value

  • 0

I am using select field1, max(updated_date) from mytable.
I get the correct value for max(updated_date), i.e. the largest date.
However for field1 I just get the the value for the first record, i.e. “ta1” when I really want the “ta3” value from the third record (the one with the max date value).

e.g.

+------------+---------------------+
| field1     | update_date         |
+------------+---------------------+
| ta1        | 2012-03-11 11:05:15 |
| ta2        | 2012-03-11 11:05:32 |
| ta3        | 2012-03-11 11:05:56 |
+------------+---------------------+
3 rows in set (0.00 sec)

+------------+---------------------+
| field1     | max(update_date)    |
+------------+---------------------+
| ta1        | 2012-03-11 11:05:56 |
+------------+---------------------+
1 row in set (0.00 sec)
  • 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-31T04:01:22+00:00Added an answer on May 31, 2026 at 4:01 am

    You either need a GROUP BY clause or a more complex query.

    SELECT field1, MAX(updated_date)
      FROM mytable
     GROUP BY field1
    

    For the sample data, this will return 3 rows.

    More likely, you want:

    SELECT t1.field1, t3.max_date
      FROM mytable AS t1
      JOIN (SELECT MAX(t2.updated_date) AS max_date
              FROM mytable AS t2
           ) AS t3
        ON t1.updated_date = t3.max_date;
    

    For the sample data, this will return 1 row:

    ta3   2012-03-11 11:05:56
    

    Of the major DBMS, only MySQL allows you to omit the GROUP BY clause when you have a mixture of aggregates and non-aggregate columns in the select-list. The SQL standard requires the GROUP BY clause and you must list all non-aggregate columns in it. Sometimes, in MySQL, omitting the GROUP BY clause produces the answer you want; as often as not, though, it manages to give an unexpected answer.

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

Sidebar

Related Questions

Just a quick question about using select() . I'm using select() to read from
I am using a SELECT query to get the data from a number of
Using a SELECT statement in MS SQL 2005 TSQL, and no source table, just
How to get size of blob ( varbinary(max) ) from SQL Server without getting
The sql query: select id,title from blog_post inner join (select object_pk, max(submit_date) from django_comments
I'm using the Datepicker in two input fields to allow users to select a
My Java NIO Selector is implemented using select() so it blocks until any of
My program accepts up to 4 connections (using select function). Once they're connect, they
Ho to do this? What query can be written by using select statement where
I'm currently using a select statement with one column as DATEPART(hh, CallTime) AS Hour

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.