0
0
MySQLquery~10 mins

JSON data type in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AJSON
BVARCHAR(255)
CTEXT
DINT
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR or TEXT instead of JSON for JSON data.
Using INT which is for numbers only.
2fill in blank
medium

Complete 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'
A'{"name": "Alice", age: 30}'
B'name: Alice, age: 30'
C'{"name": Alice, "age": 30}'
D'{"name": "Alice", "age": 30}'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing quotes around keys or string values.
Using single quotes inside JSON instead of double quotes.
3fill in blank
hard

Fix 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'
A'$.name'
B'name'
C'age'
D'$.age'
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'name' without the JSON path syntax.
Using the wrong key like 'age' instead of 'name'.
4fill in blank
hard

Fill 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'
A'$.age'
B31
C'31'
D'age'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number 31, making it a string.
Using 'age' instead of the JSON path '$.age'.
5fill in blank
hard

Fill 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'
A'$.age'
B>
C25
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for comparison.
Not using the JSON path syntax for the key.