0
0
SQLquery~20 mins

UPDATE multiple columns in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Multiple Column Updates
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output after updating multiple columns?
Given the table Employees with columns id, name, salary, and department, what will be the result of this query?

UPDATE Employees SET salary = salary + 500, department = 'HR' WHERE id = 3;

Assuming the initial row with id = 3 is {id: 3, name: 'Alice', salary: 3000, department: 'Sales'}, what will be the updated row?
SQL
UPDATE Employees SET salary = salary + 500, department = 'HR' WHERE id = 3;
A{id: 3, name: 'Alice', salary: 3000, department: 'Sales'}
B{id: 3, name: 'Alice', salary: 3500, department: 'HR'}
C{id: 3, name: 'Alice', salary: 3500, department: 'Sales'}
D{id: 3, name: 'Alice', salary: 3000, department: 'HR'}
Attempts:
2 left
💡 Hint
Remember that both columns are updated in the same query for the rows matching the condition.
🧠 Conceptual
intermediate
2:00remaining
Which SQL statement correctly updates multiple columns?
You want to update the price and stock columns in a Products table for the product with product_id = 10. Which of the following SQL statements is correct?
AUPDATE Products SET price = 20, stock = 50 WHERE product_id = 10;
BUPDATE Products SET (price, stock) = (20, 50) WHERE product_id = 10;
CUPDATE Products WHERE product_id = 10 SET price = 20, stock = 50;
DUPDATE Products SET price = 20 AND stock = 50 WHERE product_id = 10;
Attempts:
2 left
💡 Hint
The SET clause lists columns and their new values separated by commas.
🔧 Debug
advanced
2:00remaining
Identify the error in this UPDATE statement for multiple columns
Consider this SQL statement:

UPDATE Orders SET status = 'Shipped' stock = stock - 1 WHERE order_id = 100;

What error will this query produce?
ASyntax error due to missing WHERE clause
BRuntime error because stock cannot be decremented
CNo error, query runs successfully
DSyntax error due to missing comma between column assignments
Attempts:
2 left
💡 Hint
Check the syntax between multiple column assignments in the SET clause.
optimization
advanced
2:00remaining
Optimizing multiple column updates in a large table
You need to update the status and last_updated columns for 10,000 rows in a large Tasks table. Which approach is generally better for performance?
ADelete the 10,000 rows and re-insert them with updated values
BUpdate each row individually in a loop with separate UPDATE statements
CRun a single UPDATE statement that sets both columns at once with a WHERE condition matching the 10,000 rows
DRun two separate UPDATE statements, one for each column, each with the same WHERE condition
Attempts:
2 left
💡 Hint
Minimize the number of UPDATE statements to reduce overhead.
query_result
expert
3:00remaining
What is the final state after a complex multiple column UPDATE?
Given the table Inventory with columns item_id, quantity, price, and discount, and initial row:

{item_id: 5, quantity: 100, price: 10, discount: 0}

What will be the row after running this query?

UPDATE Inventory SET quantity = quantity - 20, price = price * 0.9, discount = discount + 5 WHERE item_id = 5;
SQL
UPDATE Inventory SET quantity = quantity - 20, price = price * 0.9, discount = discount + 5 WHERE item_id = 5;
A{item_id: 5, quantity: 80, price: 9, discount: 5}
B{item_id: 5, quantity: 80, price: 10, discount: 5}
C{item_id: 5, quantity: 100, price: 9, discount: 5}
D{item_id: 5, quantity: 80, price: 9, discount: 0}
Attempts:
2 left
💡 Hint
Calculate each column update step by step.