MCQ

MySQL Practice Exercises with Solutions – Part 3

We have split this collection of exercises on MYSQL into seven parts, this is the first one, then you will find the second part, the third part, the fourth part, the fifth part, the sixth part, seventh part, eighth part, and finally the ninth part these exercises are based on simple, advanced and finally complex MYSQL queries. These questions are based on the following two tables, Employee table and Reward table.
 

Employee table
+-------------+------------+-----------+----------+--------------+-------------+
| Employee_id | First_name | Last_name |  Salary  | Joining_date | Departement |
+-------------+------------+-----------+----------+--------------+-------------+
|     1       |     Bob    |   Kinto   | 1000000  |  2019-01-20  |   Finance   |
|     2       |    Jerry   |  Kansxo   | 6000000  |  2019-01-15  |     IT      |
|     3       |    Philip  |   Jose    | 8900000  |  2019-02-05  |   Banking   |
|     4       |    John    |  Abraham  | 2000000  |  2019-02-25  |  Insurance  |
|     5       |   Michael  |  Mathew   | 2200000  |  2019-02-28  |   Finance   |
|     6       |    Alex    |  chreketo | 4000000  |  2019-05-10  |     IT      |
|     7       |    Yohan   |   Soso    | 1230000  |  2019-06-20  |   Banking   |
+-------------+------------+-----------+----------+--------------+-------------+
Reward table
+-----------------+-------------+--------+
| Employee_ref_id | date_reward | amount |
+-----------------+-------------+--------+
|         1       | 2019-05-11  |  1000  | 
|         2       | 2019-02-15  |  5000  |
|         3       | 2019-04-22  |  2000  |
|         1       | 2019-06-20  |  8000  |
+-----------------+-------------+--------+
Download the file containing the SQL statements allowing the creation of these tables. (Click here)

 

 

Questions

1. Get all the details about employees whose first name begins with ‘B’.

SELECT * FROM employee WHERE First_name LIKE 'B%';


MySQL LIKEMySQL LIKEThe LIKE operator is a logical operator used in WHERE clause that tests whether a string contains a specified pattern or not. Two wildcards are…Read More

 

2. Get all the details about employees whose first name contains ‘o’.

SELECT * FROM employee WHERE First_name LIKE '%o%';

 

3. Get all the details of the employees whose first name ends with ‘n’.

SELECT * FROM employee WHERE First_name LIKE '%n';

 

4. Get all the details about employees whose first name ends with ‘n’ and contains 4 letters.

SELECT * FROM employee WHERE First_name LIKE '___n';

 

5. Get all the details about employees whose first name begins with ‘J’ and contains 4 letters.

SELECT * FROM employee WHERE First_name LIKE 'J___';

 

 
6. Get all the details of employees whose salary is over 3,000,000.

SELECT * FROM employee WHERE salary > 3000000;

 

7. Get all the details about employees whose salary is less than 3,000,000.

SELECT * FROM employee WHERE salary < 500000;

 

8. Get all the details about employees with a salary between 2,000,000 and 5,000,000.

SELECT * FROM employee WHERE salary BETWEEN 2000000 AND 5000000;


MySQL BETWEENMySQL BETWEENThe BETWEEN operator is a logical operator that allows you to specify whether a value is in a range or not. The BETWEEN operator is…Read More

 

9. Get all the details about employees whose first name is ‘Bob’ or ‘Alex’.

SELECT * FROM employee WHERE First_name in ('Bob','Alex');


How to Check if Value Exists in a MySQL DatabaseHow to Check if Value Exists in a MySQL DatabaseIn this tutorial, we are going to see how to check if a value exists in a MySQL database. The IN operator allows you to…Read More

 

10. Get all the details about employees whose joining year is “2019”.

SELECT * FROM employee WHERE YEAR(joining_date) = '2019';


How To Get Year From Date In MySQLHow To Get Year From Date In MySQLIn SQL language the YEAR() function allows extracting a year from a date in YYYY-MM-DD format.   Syntax: To use this function in a SQL…Read More

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *