• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: WO way to SELECT MAX(FOO) FROM BAR
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WO way to SELECT MAX(FOO) FROM BAR


  • Subject: Re: WO way to SELECT MAX(FOO) FROM BAR
  • From: Chuck Hill <email@hidden>
  • Date: Thu, 11 Dec 2008 13:51:53 -0800


On Dec 11, 2008, at 12:44 PM, David Avendasora wrote:

Hi all,

I've googled this, but can't seem to find any answers even though I'm guessing it's a pretty common thing.

I have a table that has nearly 2 million rows and I want to retrieve the maximum value used in the entire table for a given field. The SQL equivelent would be:

SELECT MAX(FIELD) FROM TABLE

Ideally, I'd like the whole row like this would get for me:

SELECT * FROM TABLE
WHERE ID = (SELECT MAX(ID) FROM TABLE)

but I'd be happy just to get the maximum value in that one field.

Should I just do it with straight SQL, or is there a good EOF/Wonder way to do it where I let EOF deal with the DB?

The field is indexed, so the straight SQL call is instantaneous.


Dave, Dave, Dave...

If it was me, I'd use this cool tool that I have. I think it is called a computer. You might want to get one. I hear these ones from Apple are very nice. Then, I'd search ERExtensions/Sources for "max", all case insensitive like. Who knows what I might find?

/**
* Computes an aggregate function for a given attribute
* restricted by a given qualifier. For instance
* select MAX(AGE) from User where name like 'M*'
*
* @param ec editing context used for the fetch
* @param entityName name of the entity
* @param attributeName attribute for the function to be performed on
* @param function name, ie MAX, MIN, AVG, etc.
*
* @return aggregate result of the fuction call
*/
public static Number aggregateFunctionWithQualifier(EOEditingContext ec,
String entityName,
String attributeName,
String function,
String fetchSpecificationName,
NSDictionary bindings) {




Chuck

--
Chuck Hill             Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects







_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: WO way to SELECT MAX(FOO) FROM BAR
      • From: David Avendasora <email@hidden>
References: 
 >WO way to SELECT MAX(FOO) FROM BAR (From: David Avendasora <email@hidden>)

  • Prev by Date: Re: Nightlybuild + HelloWorld with non-used Frameworks --broken
  • Next by Date: RE: Nightlybuild + HelloWorld with non-used Frameworks --broken
  • Previous by thread: WO way to SELECT MAX(FOO) FROM BAR
  • Next by thread: Re: WO way to SELECT MAX(FOO) FROM BAR
  • Index(es):
    • Date
    • Thread