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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:44:01+00:00 2026-06-09T16:44:01+00:00

Consider these two queries: SELECT *, ‘b’ AS b FROM someTable ORDER BY a

  • 0

Consider these two queries:

SELECT *, 'b'    AS b    FROM someTable ORDER BY a ASC LIMIT 1;
SELECT *, MAX(a) AS maxA FROM someTable ORDER BY a ASC LIMIT 1;

The former query returns the row with the lowest value of a, as expected. The latter query returns the first row stored on disk (usually the row with the lowest value for primary key). How can I work around this? My intention is to get the full row of the column with the lowest a value (if there is more than one I only need one, it does not matter which), and additionally I do need the value of the highest age. In a perfect world I would run two queries, but due to the way that objects are serialised in this application I cannot do that without refactoring a lot of code that isn’t mine. I actually don’t mind if the MySQL engine itself must query twice, the important bit is that the output be returned in a single row. I cannot write a stored procedure for this query, unfortunately. And yes, the * operator is important, I cannot list the needed fields. And there are too many row to return them all!

Note that this question is superficially similar to a previous question, however the question asked there was ill-formed and ambiguous, therefore all the answers addressed the issue that was not my intention (however useful, I did learn much and I’m happy that it turned out that way). This question asks the intended question more clearly and so should attract different answers.

  • 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-09T16:44:02+00:00Added an answer on June 9, 2026 at 4:44 pm

    Why not just run this:

    SELECT MIN(a) as minA, MAX(a) AS maxA FROM someTable
    

    Unfortunately, MySQL doesn’t know window functions. So if you really want to select * along with min/max values, I guess you’ll have to resort to a JOIN:

    SELECT * FROM 
    (
      SELECT * FROM someTable ORDER BY a ASC LIMIT 1
    ) t1
    CROSS JOIN
    (
      SELECT MIN(a) as minA, MAX(a) AS maxA FROM someTable
    ) t2
    

    Or to a subselect, as given in Imre L’s answer

    • 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 *, MAX(age) AS maxAge FROM someTable ORDER BY age
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
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
Consider these two tables: --Subscriber_File--- ID GenreId FileName 01 1,2 TestFile.pdf --MasterGenre-- ID Genrename
Consider these two snippets: try: a+a=a except SyntaxError: print first exception caught . try:

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.