Update Join — SQL Technical Interview Questions & Answers
Update Join
Update Join
- UPDATE students s JOIN marks m ON s.roll = m.roll SET s.marks = m.score WHERE m.subject = 'Maths'; copy a value across tables. JOIN picks the rows, SET changes them.
- Preview with SELECT s.roll, s.marks, m.score FROM … the same JOIN. Then UPDATE.
- Trap: UPDATE without JOIN when the new value lives in another table. Trap: multiple marks rows per student — which one wins is messy; be specific in WHERE.
- On the example next to this theory: Update Join — uPDATE changes existing rows — always scope with WHERE.
Technical Interview Tip: UPDATE s JOIN m ON s.roll = m.roll SET s.marks = m.score;
Code Examples for Update Join
Update Join — sample query
CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT, price REAL);
INSERT INTO products VALUES (1, 'Mouse', 499);
UPDATE products SET price = 449 WHERE id = 1;
SELECT * FROM products;Update Join — uPDATE changes existing rows — always scope with WHERE.
How to Explain Update Join to an Interviewer
How do you update from another table?
UPDATE t1 JOIN t2 ON … SET t1.col = t2.col