Re: How to do a "SELECT DISTINCT"
Re: How to do a "SELECT DISTINCT"
- Subject: Re: How to do a "SELECT DISTINCT"
- From: Sacha Mallais <email@hidden>
- Date: Tue, 22 Mar 2005 14:06:22 -0800
On Mar 22, 2005, at 1:49 pm, Chuck Hill wrote:
I'm not sure that Sacha's suggestion is what you want. If you want to
get all of the rows that have a unique name in them, then EOF is not
going to be helpful. The reason is that EOF maps objects to some
external, persistent, representation. It is very, very concerned with
maintaining the connect of an object to its external representation.
If there are multiple rows with the same name, SELECT DISTINCT will
return the data from one of them, but which one is not known.
True.
So your fetch, if it were possible, would be saying to EOF "get me
some random objects, but make sure they have unique names". It is
just not built for that. I can't even think of how to do this in SQL,
return entire rows where the values in column are unique, but its been
a while since I had to do things like that in SQL.
Definitely possible. This:
select distinct("name"), attribute from foo;
Will returns all rows from foo that have a unique name. The data you
get from the "attribute" column will be random from among the set of
rows with the same "name" value.
If you want a list of names to use in a lookup list, then you should
further normalize your data do that the unique names are held in their
own object / table.
Certainly that would be the preferred way. Another way:
NSArray names = new
NSSet(editingContext.objectsWithFetchSpecification(fetchSpec).valueForKe
y("name")).allObjects();
sacha
--
Sacha Michel Mallais - 800 lb. gorilla
Global Village Consulting Inc.: http://www.global-village.net/
ObAd: read "Practical WebObjects" <fnord>
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