SQL
NULL and Functions
A function that has input argument as `NULL` **usually** returns `NULL`.  
```sql
SELECT cos(NULL);
```  
```text
NULL
```  
The `coalesce` function is an exception to this: it takes any number of arguments, and returns for each row the first argument that is not `NULL`. If all arguments are `NULL`, `coalesce` also returns `NULL`.  
```sql
SELECT coalesce(NULL, NULL, 1);
```  
```text
1
```  
```sql
SELECT coalesce(10, 20);
```  
```text
10
```  
```sql
SELECT coalesce(NULL, NULL);
```  
```text
NULL
```  
The `ifnull` function is a two-argument version of `coalesce`.  
```sql
SELECT ifnull(NULL, 'default_string');
```  
```text
default_string
```  
```sql
SELECT ifnull(1, 'default_string');
```  
```text
1
```