Salesforce equivalent of "SELECT DISTINCT"?

John Mee picture John Mee · Mar 2, 2018 · Viewed 17.6k times · Source

I want to know what all the existing values of a field are.

In SQL that would be something like:

SELECT DISTINCT foo
FROM bar

How might I do this with salesforce's SOQL?

Answer

John Mee picture John Mee · Mar 2, 2018

Use Group by

SELECT foo
FROM bar
GROUP BY foo

eg:

SELECT Status
FROM Case
GROUP BY Status

1|New
2|Assigned
3|In Progress
4|In Progress Known Issue