Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a table with a JSON column named 'data'.
MySQL
CREATE TABLE users (id INT PRIMARY KEY, data [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR or TEXT instead of JSON for JSON data.
Using INT which is for numbers only.
✗ Incorrect
The JSON data type allows storing JSON documents directly in MySQL.
2fill in blank
mediumComplete the query to insert a JSON object into the 'data' column.
MySQL
INSERT INTO users (id, data) VALUES (1, [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing quotes around keys or string values.
Using single quotes inside JSON instead of double quotes.
✗ Incorrect
JSON strings must have keys and string values in double quotes.
3fill in blank
hardFix the error in the query to select the 'name' from the JSON column 'data'.
MySQL
SELECT data->>[1] FROM users WHERE id = 1;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'name' without the JSON path syntax.
Using the wrong key like 'age' instead of 'name'.
✗ Incorrect
Use the JSON path '$.name' to extract the 'name' key from JSON.
4fill in blank
hardFill both blanks to update the 'age' in the JSON column to 31 for user with id 1.
MySQL
UPDATE users SET data = JSON_SET(data, [1], [2]) WHERE id = 1;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number 31, making it a string.
Using 'age' instead of the JSON path '$.age'.
✗ Incorrect
Use JSON_SET with the JSON path '$.age' and the new integer value 31.
5fill in blank
hardFill all three blanks to select users where the JSON 'age' is greater than 25.
MySQL
SELECT * FROM users WHERE JSON_EXTRACT(data, [1]) [2] [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for comparison.
Not using the JSON path syntax for the key.
✗ Incorrect
Use JSON_EXTRACT with '$.age' and compare with > 25 to filter users older than 25.