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      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to