UPSERT
Upsert = insert or update if the key exists. MySQL: INSERT … ON DUPLICATE KEY UPDATE … or REPLACE (harsher). Example: refresh Asha’s marks if roll 12 exists, else insert.
Needs a PRIMARY/UNIQUE key to detect ‘exists’.
Trap — upsert without a unique key — always inserts.
On the example next to this theory: UPSERT: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Exam tip
INSERT … ON DUPLICATE KEY UPDATE marks = 90;