Quick Ref.
Functions
date
number
string
Data Types
date
number
string

Teachers and Departments

The school includes many departments. Most teachers work exclusively for a single department. Some teachers have no department.

teacher
iddeptname phonemobile
1011Shrivell275307986 555 1234
1021Throd275407122 555 1920
1031Splint2293
104Spiregrain3287
1052Cutflower321207996 555 6574
...............
dept
id name
1Computing
2Design
3Engineering

Selecting NULL values

NULL, INNER JOIN, LEFT JOIN, RIGHT JOIN

1a. List the teachers who have NULL for their department.

Results
1b. Note the INNER JOIN misses the teacher with no department and the department with no teacher.

Results
1c. Use a different JOIN so that all teachers are listed.

Results
1d. Use a different JOIN so that all departments are listed.

Results

Using the COALESCE function

2a. Use COALESCE to print the mobile number. Use the number '0131 444 2266' there is no number given.

Show teacher name and mobile number or '07986 444 2266'


Results
2b. Use the COALESCE function and a LEFT JOIN to print the name and department name number. Use the string 'None' where there is no department.

Results
2c. Use COUNT to show the number of teachers and the number of mobile phones.

Results
2d. Use COUNT and GROUP BY dept.name to show each department and the number of staff. Use a RIGHT JOIN to ensure that the Engineering department is listed..

Results

Using CASE

3a. Use CASE to show the name of each teacher followed by 'Sci' if the the teacher is in dept 1 or 2 and 'Art' otherwise.

Results
3b. Use CASE to show the name of each teacher followed by 'Sci' if the the teacher is in dept 1 or 2 show 'Art' if the dept is 3 and 'None' otherwise.

Results