You need to sign in to do that
Don't have an account?
Motoki
SOQL HELP!!!
Hi guys,
When i used the following query to select from data from a custom objects i get a lot of repeated data.
Select bandName__c From Bands__c Where Genre_ID__c = 1
I tried to used a keyword "distinct" in SQL language but this gives me an error... So, is there any way i can remove the repeated data??
Many Thanks,
Motoki
I assume you are getting repeated data in response to your queries because you have repeated data in the Bands object. The way to elminate this would be to implement the data as two related objects. For instance, instead of having data like this
Band Genre
The Band Country
The Band Rock
The Band Soul
you would have one object with the name of the band and another with Genre, with a one to many relationship between the band object and the genre object.
SOQL doesn't support the distince keyword, but you can get the same effect with appropriate data design.
Hope this helps.
- Rick Greenwald
Developer Evangelist
However, if there is duplicate data:
Band Genre
The Band Country
The Band Rock
The Band Soul
The Band Country
"The Band" would be returned two times with the same query.
Duplicate data could occur if "songs" are captured on the same "Band" object (two different songs by the same band with the same genre, for example).
The following query would return only one result based on the above sample database:
Select bandName__c From Bands__c Where Genre_ID__c = 1 Limit 1
(keep in mind, however, that this query would return only the first match found, and no other matches!)
As Ricky mentioned, the appropriate data design would produce the desired result.
Message Edited by CaptainObvious on 07-30-2007 01:31 PM