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

Instruction

Oops... The English teacher just realized that she accidentally switched written_exam_scores and oral_exam_scores. The last UPDATE introduced this mistake to the exam table, for all records for English exams. How can we correct this? Look at the query below:

UPDATE exam
SET 
  written_exam_score = oral_exam_score,
  oral_exam_score = written_exam_score
WHERE subject = 'English'

We set new values for two columns: written_exam_score and oral_exam_score. The first column took the value from oral_exam_score, and the second column took the value from written_exam_score. SQL makes this operation easy.

Exercise

It's time to fix another mistake in our database. Somebody mistook the first name of the student whose ID is 6 for his last name. See if you can use the example query to correct this.