Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting and updating NULLs
6. UPDATE with NULL in SET
Conditions in UPDATE and DELETE
Updating the list of columns in one query
Using values from another column
Return rows in INSERT, UPDATE, DELETE
Summary

Instruction

Fantastic! You already know how to insert data with NULLs. You can also use NULL in UPDATE statements.

Suppose the teacher made a mistake. Tom Muller took the written exam, but the teacher hasn't checked this exam (exam ID of 17). Nevertheless, Tom has the score of the written exam (written_exam_score) and the date (written_score_date), but he shouldn't. In this case, the only known value is the actual date of the written exam; you must remove the other two values. How would you do this?

It's simple! Look at the command below:

UPDATE exam 
SET 
  written_exam_score = NULL, 
  written_score_date = NULL
WHERE id = 17;

After SET, we used two comma-separated column names to update written_exam_score and written_score_date. Each column was assigned NULL. In the WHERE condition, we update only the exam with id = 17. In this way, we correct our mistake.

Exercise

In the database, the teacher stores the student named Laura Donna Ross (id = 10). However, Laura doesn't have a middle name; Donna is a mistake. Correct this mistake by updating the data.