You need to sign in to do that
Don't have an account?
Suchitra
Distinct in soql
Hi,
I would like to know is there any ways to get distinct records in soql
I want to extract the product family using a query I get all the records having family but I want only distinct records how do I do that ?
Thanks in advance
Suchitra
Adam is, of course, right - SOQL is not SQL, and it does not support the key word DISTINCT.
But that doesn't mean you can't achieve the same result. SOQL naturally uses the concept of relationships, such as a lookup relationship, between objects. You might be able to design your custom objects to store the possible values for a product family in one table, and have all the records in another custom object have a lookup relation to a single value.
In other words, instead of having data that looks like this
Product Name Product Family
Product One Product Family 1
Product Two Product Family 1
Product Three Product Family 1
Product Four Product Family 2
Product Five Product Family 2
You would have one custom object called Product Name, with the names, and another called Product Family, with two records for Product Family 1 and Product Family 2. You would then have a SOQL query that selected on the distinct product family value and also retrieved the related product names.
Of course, creating separate objects like this has implications in the design and implementation of other parts of your application, which may be helpful or hurtful.
Finally, you can always retrieve all the records into an SObject and then remove duplicates through code.
Hope this helps.
- Rick Greenwald
Salesforce.com Evangelist
Thanks a lot Rick I will try this out.:smileyhappy:
Thanks & Regards
P Suchitra