w3resource
MySQL exercises

MySQL Exercises, Practice, Solution

MySQL Restricting and Sorting data: [11 exercises with solution]

1. Write a query to display the name (first_name, last_name) and salary for all employees whose salary is not in the range $10,000 through $15,000. Go to the editor

Sample table: employees


Click me to see the solution

2. Write a query to display the name (first_name, last_name) and department ID of all employees in departments 30 or 100 in ascending order. Go to the editor

Sample table: employees


Click me to see the solution

3. Write a query to display the name (first_name, last_name) and salary for all employees whose salary is not in the range $10,000 through $15,000 and are in department 30 or 100. Go to the editor

Sample table: employees


Click me to see the solution

4. Write a query to display the name (first_name, last_name) and hire date for all employees who were hired in 1987. Go to the editor

Sample table: employees


Click me to see the solution

5. Write a query to display the first_name of all employees who have both "b" and "c" in their first name. Go to the editor

Sample table: employees


Click me to see the solution

6. Write a query to display the last name, job, and salary for all employees whose job is that of a Programmer or a Shipping Clerk, and whose salary is not equal to $4,500, $10,000, or $15,000. Go to the editor

Sample table: employees


Click me to see the solution

7. Write a query to display the last name of employees whose names have exactly 6 characters. Go to the editor

Sample table: employees


Click me to see the solution

8. Write a query to display the last name of employees having 'e' as the third character. Go to the editor

Sample table: employees


Click me to see the solution

9. Write a query to display the jobs/designations available in the employees table.Go to the editor

Sample table: employees


Click me to see the solution

10. Write a query to display the name (first_name, last_name), salary and PF (15% of salary) of all employees. Go to the editor

Sample table: employees


Click me to see the solution

11. Write a query to select all record from employees where last name in 'BLAKE', 'SCOTT', 'KING' and 'FORD'. Go to the editor

Sample table: employees


Click me to see the solution

... More

Structure of 'hr' database:

hr database

MySQL Code Editor:

Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.