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

  • Home
  • SEARCH
  • 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 8395195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:14:23+00:00 2026-06-09T20:14:23+00:00

Consider these two queries: SELECT *, MAX(age) AS maxAge FROM someTable ORDER BY age

  • 0

Consider these two queries:

SELECT *, MAX(age) AS maxAge FROM someTable ORDER BY age ASC;
SELECT *, 'dummyC' AS dummyC FROM someTable ORDER BY age ASC;

The former query returns all rows and all columns of the table, plus an additional dummy column. The later query returns only a single row, that row which has the lowest primary key. Why is that, and how can I work around it? Tested in MySQL 5.1 on some old but stable Debian server.

  • 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-09T20:14:25+00:00Added an answer on June 9, 2026 at 8:14 pm

    This is a MySQL extension.

    MySQL extends the use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BY clause. This means that the preceding query is legal in MySQL. You can use this feature to get better performance by avoiding unnecessary column sorting and grouping. However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate. Furthermore, the selection of values from each group cannot be influenced by adding an ORDER BY clause. Sorting of the result set occurs after values have been chosen, and ORDER BY does not affect which values the server chooses.

    The value you get is indeterminate. You will often get the first row that was inserted into the table, but this is not guaranteed.

    If you want the corresponding values from the row containing the highest age then it is better to use a combination of ORDER BY and LIMIT 1:

    SELECT *
    FROM someTable
    ORDER BY age DESC
    LIMIT 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider these two queries: SELECT *, 'b' AS b FROM someTable ORDER BY a
Consider these two similar SQLs (condition in ON clause) select t1.field1, t2.field1 from table1
Consider these three mysql statements: select * from Users; select id, title, value from
How does EmailProperty differ from StringProperty ? Consider these two examples: # example 1:
Consider these two classes mapped to the same table. One is readonly via mutable=false.
I ran across a compilation issue today that baffled me. Consider these two container
I would like to determine two things from a single query: Most prevalent column
I have a SQL query that I'm currently solving by doing two queries. I
Consider these two functions: 'Overload 1 <Extension()> Function ComputeReturnValue(Of TSource, TResult)(ByVal source As TSource,
In my application, I have two queries that occur from time to time (from

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.