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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:40:14+00:00 2026-05-30T22:40:14+00:00

I need to get the ID based from what ever the max amount is.

  • 0

I need to get the ID based from what ever the max amount is. Below is giving me an error

   select  ID from Prog 
   where Amount = MAX(Amount)

An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

The end result is that I need to get the just the ID as I need to pass it something else that is expecting it.

  • 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-30T22:40:15+00:00Added an answer on May 30, 2026 at 10:40 pm

    You need to order by Amount and select 1 record instead…

    SELECT ID
    FROM Prog
    ORDER BY Amount DESC
    LIMIT 1;
    

    This takes all the rows in Prog, orders them in descending order by Amount (in other words, the first sorted row has the highest Amount), then limits the query to select only one row (the one with the highest Amount).

    Also, subqueries are bad for performance. This code runs on a table with 200k records in half the time as the subquery versions.

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

Sidebar

Related Questions

I need to get a regular snapshot from a webcam in Delphi. Speed is
I'm try to get a point based structure from a function called: -(NSArray *)
I need to get 5 random records from a table plus a further record
I am implementing a MKMapView based application. In that I need to get all
I need to get data from an Excel file to print them in a
I designed a WPF application based on MVVM pattern and I need to get
My goal is to get a weighted average from one table, based on another
I am using http://code.google.com/apis/maps/documentation/geocoding/ api from google to get geolocation based on address. I
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need get all items these have no categories int? categoryId = null; var

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.