# Using INCLUDE NULLS with UNPIVOT in BigQuery

While solving a bug I was reminded *again* that, when UNPIVOTing, rows with NULL values are excluded. Fine.

But it turns out we have the option to specify the INCLUDE NULLS with UNPIVOT, thus allowing us to keep those rows in the result set.

Let's look at an example.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708177572891/887dd017-f882-4d61-b6e5-9dc5b2ee4a41.png align="center")

This is how it would look if UNPIVOTed as usual:

```sql
SELECT 
    measurement_date, 
    value, 
    measurement 
FROM input
UNPIVOT INCLUDE NULLS (value FOR measurement IN (water_level, temperature, pressure))
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708177661538/32001304-5d4f-436d-b9e8-8953c858be30.png align="center")

As you notice, we don't have the rows where the measurement values are NULL.

How can we fix it? Let's use UNPIVOT in conjunction with `INCLUDE NULLS`.

```sql
SELECT 
    measurement_date, 
    value, 
    measurement 
FROM input
UNPIVOT INCLUDE NULLS (value FOR measurement IN (water_level, temperature, pressure))
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708177753576/8b53cd0f-265b-4f07-a418-4fe42d3704ee.png align="center")

Voila! The NULL entries are here now.

*Found it useful? Subscribe to my Analytics newsletter at* [*notjustsql.com*](https://www.notjustsql.com)*.*
