---
title: "DB2- Use of ‘COALESCE’ Function (1 of 2)"
description: "The \"COALESCE\" function is one of the frequently used functions in DB2. Before going into detail, I just want to describe it in layman terms. https://srinimf.com/2015/11/08/nvl-and-coalesce-functions-..."
url: https://srinimf.com/2012/04/19/db2-use-of-coalesce-function/
date: 2012-04-19
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2012/04/db2-functions-e1539399132908.jpg?fit=500%2C317&ssl=1
categories: ["DB2", "DB2 V11"]
tags: ["COALESCE", "db2"]
type: post
lang: en
---

# DB2- Use of ‘COALESCE’ Function (1 of 2)

The “COALESCE” function is one of the [frequently used](https://srinimf.com/2022/05/09/10-python-string-in-built-methods-all-you-need/) functions in DB2. Before going into detail, I just [want to](https://srinimf.com/2016/02/09/want-to-excel-in-ims-dc-programming-read-this/) describe it in layman terms.

Related[NVL and COALESCE Functions Basic Differences in DB2](https://srinimf.com/2015/11/08/nvl-and-coalesce-functions-basic-differences-in-db2/)

This function validates for NULL, and secondly, if NULL is there it assumes some value as we give in the function.

```
Syntax: COALESCE(epression1,expression2)
```

It is like decision maker. Its uses are many.

#### **Usage-1:**

CASE WHEN expression1 IS NOT NULL THEN expression1 ELSE expression2 END.

#### In other way we can write:

CASE COALESCE(expression1,expression2) END.

#### **Usage-2:**

WHERE COALESCE (MARKS1,0) + MARKS2 > 100

If MARKS1 is null it assumes as zero ‘0’.

### **Usage-3:**

SELECT COALESCE(EMP.DEPT,ROLE.DEPT) AS DEPT. In this case neither of the DEPT of EMP and ROLE tables is NULL. In my next I will give more on this function.

Related[SQL Query: How to Find Salary Dept wise](https://srinimf.com/2015/06/12/db2-sql-query-to-find-salary-dept-wise/)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2012%2F04%2F19%2Fdb2-use-of-coalesce-function%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2012%2F04%2Fdb2-functions-e1539399132908.jpg%3Ffit%3D500%252C317%26ssl%3D1&description=DB2-%20Use%20of%20%27COALESCE%27%20Function%20%281%20of%202%29)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2012/04/19/db2-use-of-coalesce-function/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2012/04/19/db2-use-of-coalesce-function/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2012/04/19/db2-use-of-coalesce-function/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2012/04/19/db2-use-of-coalesce-function/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20DB2-%20Use%20of%20%27COALESCE%27%20Function%20%281%20of%202%29&body=https%3A%2F%2Fsrinimf.com%2F2012%2F04%2F19%2Fdb2-use-of-coalesce-function%2F&share=email)
-

### Like this:

Like Loading…
