---
schema_version: "1"
id: ef4cd152ec3b05022e8b415a4a14d59bc7b99878098d8a6cad7ed74aa662dd05
title: COALESCE()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_sql/guides/bi-sql-coalesce.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-sql/guide/bi-sql-coalesce.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e6e3a4da1cc3886d574a19da31ede4ae7c4e5bda8a6a86440b03d582d2338dfa
products:
  - SQL for Analytics Developer Guide
  - analytics
---

# COALESCE()

You can use the `coalesce()`function as shorthand for case statements. The `coalesce()` function replaces null values in your dataset with another value. The function takes a series of arguments and returns the first value that is not null.

In this query, the first case statement says that if the City value is not null, return the City value. Otherwise, return `NULL`. For the second case, it says if a Country value is not null, return the Country. If it is null, return the string "Unknown."

```nolang
SELECT CASE WHEN City
IS NOT NULL
THEN City
ELSE NULL
END AS City,
CASE WHEN Country
IS NOT NULL
ELSE 'Unknown'
END As Country
FROM "Superstore"
Group by City, Country;

```

Here's the same query rewritten with `coalesce().`

```nolang
SELECT COALESCE(City, NULL) as City, COALESCE(Country, 'Unknown') as Country
FROM "Superstore"
GROUP BY City, Country;
```

There are no null City or Country values in the first five results returned from the query.

| City        | Country       |
| ----------- | ------------- |
| Aberdeen    | United States |
| Abilene     | United States |
| Akron       | United States |
| Albuquerque | United States |
| Alexandria  | United States |
