0
0
MySQLquery~10 mins

REPLACE function 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 replace all occurrences of 'cat' with 'dog' in the column 'pet' from the table 'animals'.

MySQL
SELECT REPLACE(pet, [1], 'dog') FROM animals;
Drag options to blanks, or click blank then click option'
A'cat'
B'dog'
C'pet'
D'animal'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong string to replace, like 'dog' instead of 'cat'.
Confusing the order of arguments in REPLACE.
2fill in blank
medium

Complete the code to replace all spaces with underscores in the 'username' column of the 'users' table.

MySQL
SELECT REPLACE(username, [1], '_') FROM users;
Drag options to blanks, or click blank then click option'
A' '
B'_'
C'-'
D'space'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '_' as the string to find instead of the replacement.
Using the word 'space' instead of the space character.
3fill in blank
hard

Fix the error in the code to replace 'old' with 'new' in the 'description' column from 'products'.

MySQL
SELECT REPLACE(description, [1], 'new') FROM products;
Drag options to blanks, or click blank then click option'
Aold
Bdescription
C"old"
D'old'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around string literals.
Using double quotes which may not work in MySQL for strings.
4fill in blank
hard

Fill both blanks to replace 'blue' with 'red' in the 'color' column from 'items' table.

MySQL
SELECT REPLACE(color, [1], [2]) FROM items;
Drag options to blanks, or click blank then click option'
A'blue'
B'red'
C'green'
D'yellow'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of the strings.
Using wrong strings that don't match the task.
5fill in blank
hard

Fill all three blanks to replace 'cat' with 'dog' in the 'pet' column and rename the output column as 'new_pet' in the 'animals' table.

MySQL
SELECT REPLACE([1], [2], [3]) AS new_pet FROM animals;
Drag options to blanks, or click blank then click option'
Apet
B'cat'
C'dog'
Danimals
Attempts:
3 left
💡 Hint
Common Mistakes
Using table name instead of column name.
Not quoting the strings to find and replace.