Challenge - 5 Problems
Master of UPDATE with expressions
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of UPDATE with arithmetic expression
Given a table products with columns
id, price, and stock, what will be the price of the product with id = 2 after running this query?UPDATE products SET price = price + 10 WHERE id = 2;
SQL
SELECT price FROM products WHERE id = 2;
Attempts:
2 left
💡 Hint
Think about how the expression modifies the current price value.
✗ Incorrect
The UPDATE statement adds 10 to the current price of the product where id equals 2, increasing its price by 10.
❓ query_result
intermediate2:00remaining
Result of UPDATE with string concatenation
Consider a table users with columns
id and username. What will be the new username for the user with id = 1 after executing?UPDATE users SET username = username || '_2024' WHERE id = 1;
SQL
SELECT username FROM users WHERE id = 1;
Attempts:
2 left
💡 Hint
The operator || concatenates strings in SQL.
✗ Incorrect
The UPDATE appends '_2024' to the existing username for the user with id 1.
📝 Syntax
advanced2:00remaining
Identify the syntax error in UPDATE with expression
Which option contains a syntax error in the UPDATE statement that tries to increase salary by 5% for employees in department 10?
Attempts:
2 left
💡 Hint
Check how percentages are expressed in SQL arithmetic.
✗ Incorrect
Option A uses '5%' which is not valid syntax in SQL arithmetic expressions; percentages must be expressed as decimals.
🔧 Debug
advanced2:00remaining
Why does this UPDATE not change any rows?
Given a table orders with columns
order_id, status, and quantity, why does this query not update any rows?UPDATE orders SET quantity = quantity + 1 WHERE status = 'shipped' AND quantity < 0;
Attempts:
2 left
💡 Hint
Think about the data values that satisfy the WHERE condition.
✗ Incorrect
The condition requires quantity to be less than 0, but no such rows exist with status 'shipped', so no rows are updated.
🧠 Conceptual
expert3:00remaining
Effect of multiple expressions in UPDATE
What will be the final values of
score and level columns after running this query on a table players with one row where score = 100 and level = 2?UPDATE players SET score = score + 50, level = level * 2 WHERE level = 2;
SQL
SELECT score, level FROM players WHERE level = 4;
Attempts:
2 left
💡 Hint
Both columns are updated in the same statement; the WHERE filters rows before update.
✗ Incorrect
The row with level 2 matches the WHERE clause, so score increases by 50 (100 + 50 = 150) and level doubles (2 * 2 = 4).