Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL String - Exercises, Practice, Solution

MySQL string [17 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.]

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 '@example.com' 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 from those job titles which contains more than one words. 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 to Come !

MySQL Code Editor:


Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.