# Write a SOQL query to count the number of unique Industry values across all Accounts (SELECT COUNT_DISTINCT(Industry) FROM Account).

**Topic:** Development · **Difficulty:** Easy · **Asked at:** Cognizant, Infosys, Mindtree · **Tags:** soql, scenario, aggregate

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-count-the-number-of-unique-industry-values-across-all-accounts-select-count-distinct

## Answer

Use `COUNT_DISTINCT()` on the field. It counts unique non-null values.

```soql
SELECT COUNT_DISTINCT(Industry) FROM Account
```
In Apex, the result is an `AggregateResult` and you read it with `(Integer) ar.get('expr0')`.

---
Source: ForceChallenges · last updated 2026-10-19
