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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:16:29+00:00 2026-06-03T04:16:29+00:00

This should sound stupid, but I never got why aggregate functions limit the records

  • 0

This should sound stupid, but I never got why aggregate functions limit the records returned to 1. More than any practical reason, this is just to know.

id
1 
2
3
4

Now SELECT id FROM table yields

id
1 
2
3
4

If I do SELECT id, id, 1 AS p FROM table it gives

id    id p
1     1  1
2     2  1
3     3  1
4     4  1

So next I assume SELECT id, MAX(2) AS p FROM table yields in

id   p
1    2
2    2
3    2
4    2

But this actually gives:

id   p
1    2

1) Why do this happen with aggregate functions and not give my expected result?

2) I found this with MySQL and SQLite. Do all databases respond the same?

3) Out of curiosity let me ask, how do I query to get a view like this:

id   max(id)
1    4
2    4
3    4
4    4
  • 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-03T04:16:31+00:00Added an answer on June 3, 2026 at 4:16 am

    1) You cannot execute this expression because ID is not in the aggregate function. Aggregate functions can only be used when they are the only column in the selection. This is because they return a single value and other columns mostly return more than one row.

    2) I tried this in Access and got an error. (ID not in aggregate function…). I did not try this for other database systems yet.

    3) You can get your result by adding GROUP BY ID at the end of the statement. This tells the system that you want to use each result of the aggregate function on every instance of ID. This enables you to use ID outside of the aggregate function.

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

Sidebar

Related Questions

This should be simple, but the answer is eluding me. If I've got a
This should be a common scenario, but could not find any relevant post yet..
This might sound stupid, but why doesn't the Java compiler warn about the expression
Since I'm pretty new this question'll certainly sound stupid but I have no idea
this might sound like a stupid question, but i want to clarify a concept:
I know this sounds stupid, but look at this simple example (working dir should
This question might sound a bit stupid but here it goes. I have two
This might sound like a stupid question, but who is the target audience for
Should sound weird, but this is just for my hobby. I would want a
This may sound a bit stupid but this is how I am getting it

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.