# Teacher Department Data

## 5. **Show teacher name and mobile number or '07986 444 2266'**

Use COALESCE to print the mobile number. Use the number '07986 444 2266' if there is no number given.

```php
SELECT name, COALESCE(mobile, '07986 444 2266') AS mobile
FROM teacher;
```

COALESCE takes any number of arguments and returns the first value that is not null.

```php
  COALESCE(x,y,z) = x if x is not NULL
  COALESCE(x,y,z) = y if x is NULL and y is not NULL
  COALESCE(x,y,z) = z if x and y are NULL but z is not NULL
  COALESCE(x,y,z) = NULL if x and y and z are all NULL
```

We can also use CASE WHEN:

```php
SELECT name, (CASE WHEN mobile IS NOT NULL THEN mobile ELSE '07986 444 2266' END)AS mobile
FROM teacher;
```

## 9. show the **name** of each teacher followed by 'Sci' if the teacher is in **dept** 1 or 2 and 'Art' otherwise

Using CASE operator:

```php
SELECT name,
    (CASE
    WHEN dept IN (1, 2) THEN 'Sci'
    ELSE 'Art'
    END) AS type
FROM teacher;
```

Using IF() function:

```php
SELECT name,
    IF(dept IN (1, 2), 'Sci', 'Art') AS type
FROM teacher;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lei-d.gitbook.io/sql/sqlzoo/teacher-department-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
