Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting and updating NULLs
7. IS NULL in UPDATE
Conditions in UPDATE and DELETE
Using values from another column
Inserting data from a query
Summary

Instruction

Very nice! You're familiar with using NULL in an UPDATE operation. However, sometimes we need to complete data that has some information missing. For example, say that students' written exams have been scored, but we haven't recorded the date when the exams were scored. The teacher would like to assign the date 2018-11-20 to the relevant column. Look at the command that will resolve this problem:

UPDATE exam
SET written_score_date = '2018-11-20'
WHERE written_score_date IS NULL
  AND written_exam_score IS NOT NULL;

In SET, we assign a new value to the written_score_date column. However, this value will be changed only when there is a NULL in the column and the written exam score is not NULL. The IS NULL allows us to check that.

Exercise

Some students didn't receive any scores on a written exam—the teacher forgot to enter their scores. Correct this mistake by assigning all missing written exam values a score of 43.