w3resource logo


MySQL exercises

MySQL String - Exercises, Practice, Solution

Secondary Nav

MySQL string [17 exercises with solution]

1. Write a query to get the job_id and related employee's id. Go to the editor
Partial output of the query :

job_id Employees ID
AC_ACCOUNT 206
AC_MGR 205
AD_ASST 200
AD_PRES 100
AD_VP 101 ,102
FI_ACCOUNT 110 ,113 ,111 ,109 ,112

Sample table: employees

Click me to see the solution

2. Write a query to update the portion of the phone_number in the employees table, within the phone number the substring '124' will be replaced by '999'.

Sample table: employees

Click me to see the solution

3. Write a query to get the details of the employees where the length of the first name greater than or equal to 8. Go to the editor

Sample table: employees

Click me to see the solution

4. Write a query to display leading zeros before maximum and minimum salary. Go to the editor

Sample table: jobs

Click me to see the solution

5. Write a query to append [email protected]' to email field.

Sample table: employees

Sample Output :

  EMAIL
  --------------------
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  - - - -  - - - - - - -
  - - - -  - - - - - - -

Click me to see the solution

6. Write a query to get the employee id, first name and hire month. Go to the editor

Sample table: employees

Click me to see the solution

7. Write a query to get the employee id, email id (discard the last three characters). Go to the editor

Sample table: employees

Click me to see the solution

8. Write a query to find all employees where first names are in upper case. Go to the editor

Sample table: employees

Click me to see the solution

9. Write a query to extract the last 4 character of phone numbers. Go to the editor

Sample table: employees

Click me to see the solution

10. Write a query to get the last word of the street address. Go to the editor

Sample table: locations

Click me to see the solution

11. Write a query to get the locations that have minimum street length. Go to the editor

Sample table: locations

Click me to see the solution

12. Write a query to display the first word in job title. Go to the editor

Sample table: jobs

Click me to see the solution

13. Write a query to display the length of first name for employees where last name contain character 'c' after 2nd position. Go to the editor

Sample table: employees

Click me to see the solution

14. Write a query that displays the first name and the length of the first name for all employees whose name starts with the letters 'A', 'J' or 'M'. Give each column an appropriate label. Sort the results by the employees' first names. Go to the editor

Sample table: employees

Click me to see the solution

15. Write a query to display the first name and salary for all employees. Format the salary to be 10 characters long, left-padded with the $ symbol. Label the column SALARY. Go to the editor

Sample table: employees

Click me to see the solution

16. Write a query to display the first eight characters of the employees' first names and indicates the amounts of their salaries with '$' sign. Each '$' sign signifies a thousand dollars. Sort the data in descending order of salary. Go to the editor

Sample table: employees

Click me to see the solution

17. Write a query to display the employees with their code, first name, last name and hire date who hired either on seventh day of any month or seventh month in any year. Go to the editor

Sample table: employees

Click me to see the solution

... More

MySQL Code Editor:







Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables