wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Special DB Exam

Total questions: 75

Worksheet time: 25mins

Name
Class
Date
1.

Which of the following is the correct MySQL command to create a database?

a)

CREATE TABLE database_name;

b)

CREATE DATABASE database_name;

c)

NEW DATABASE database_name;

d)

CREATE SCHEMA database_name;

2.

Which of the following queries will return employees who have a salary greater than the average salary of all employees?

a)

SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

b)

SELECT * FROM employees WHERE salary = AVG(salary);

c)

SELECT * FROM employees WHERE salary > (SELECT MAX(salary) FROM employees);

d)

SELECT * FROM employees WHERE salary > 5000;

3.

Which of the following SQL commands is used to prevent new records from being inserted into a table?

a)

DISABLE INSERT INTO table_name;

b)

ALTER TABLE table_name ADD DISABLE_INSERT;

c)

LOCKS TABLES table_name WRITE;

d)

ALTER TABLE table_name SET INSERT RESTRICT;

e)

NO ANSWER

4.

What is the result of the following query?

SELECT employee_id, salary FROM employees ORDER BY salary DESC LIMIT 3 OFFSET 2;

a)

The query will return the 3rd, 4th, and 5th highest salaries.

b)

The query will return the top 3 highest salaries.

c)

The query will return the 2nd, 3rd, and 4th highest salaries.

d)

The query will return the top 2 highest salaries starting from the 3rd highest.

5.

What does the following SQL statement do?

SELECT COUNT(*) FROM employees WHERE department_id IS NULL;

a)

Counts the number of employees in the employees table.

b)

Counts the number of employees with no department.

c)

Counts the number of NULL values in the department_id column

d)

Counts the total number of rows in the employees table.

6.

Which of the following queries will return the second highest salary from the employees table?

a)

SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);

b)

SELECT MIN(salary) FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;

c)

SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;

d)

SELECT salary FROM employees ORDER BY salary LIMIT 1 OFFSET 2;

7.

Which statement will return the count of employees per department, including departments with zero employees?

a)

SELECT department_id, COUNT(employee_id) FROM employees GROUP BY department_id;

b)

SELECT d.department_id, COUNT(e.employee_id) FROM departments d LEFT JOIN employees e ON d.department_id = e.department_id GROUP BY d.department_id;

c)

SELECT department_id, COUNT(*) FROM employees WHERE department_id IS NOT NULL GROUP BY department_id;

d)

SELECT department_id, COUNT(*) FROM employees GROUP BY department_id WITH NULLS;

8.

Which query is correct to get the first 10 records from a table employees sorted by salary in descending order?

a)

SELECT * FROM employees ORDER BY salary DESC LIMIT 10;

b)

SELECT * FROM employees LIMIT 10 ORDER BY salary DESC;

c)

SELECT TOP 10 * FROM employees ORDER BY salary DESC;

d)

SELECT * FROM employees WHERE salary > 1000 LIMIT 10;

9.

How would you modify a column salary in the employees table to allow NULL values?

a)

ALTER TABLE employees MODIFY salary INT NULL;

b)

ALTER TABLE employees CHANGE salary salary INT NULL;

c)

ALTER TABLE employees MODIFY salary SET NULL;

d)

ALTER TABLE employees ALTER salary SET NULL;

10.

Which of the following queries will return the total salary per department, excluding departments with no employees?

a)

SELECT department_id, SUM(salary) FROM employees GROUP BY department_id HAVING COUNT(employee_id) > 0;

b)

SELECT department_id, SUM(salary) FROM employees GROUP BY department_id HAVING salary > 0;

c)

SELECT department_id, SUM(salary) FROM employees GROUP BY department_id HAVING COUNT(*) > 0;

d)

SELECT department_id, SUM(salary) FROM employees WHERE department_id IS NOT NULL GROUP BY department_id;

11.

Which query retrieves all employees whose names start with the letter "J" and ends with "n"?

a)

SELECT * FROM employees WHERE name LIKE 'J%n';

b)

SELECT * FROM employees WHERE name LIKE 'J?n';

c)

SELECT * FROM employees WHERE name LIKE '%Jn%';

d)

SELECT * FROM employees WHERE name LIKE 'J_n';

12.

Which query will return the employees who do not have a manager?

a)

SELECT * FROM employees WHERE manager_id IS NULL;

b)

SELECT * FROM employees WHERE manager_id = NULL;

c)

SELECT * FROM employees WHERE manager_id IS NOT NULL;

d)

SELECT * FROM employees WHERE manager_id = 0;

13.

How would you retrieve all unique employee_id values from the employees table that are not null?

a)

SELECT DISTINCT employee_id FROM employees WHERE employee_id IS NOT NULL;

b)

SELECT employee_id FROM employees WHERE employee_id != NULL;

c)

SELECT UNIQUE employee_id FROM employees;

d)

SELECT employee_id FROM employees GROUP BY employee_id;

14.

What does the following query return?

SELECT ROUND(AVG(salary), 2) FROM employees;

a)

It rounds the salary values to 2 decimal places and returns the average.

b)

It returns the average salary rounded to the nearest integer.

c)

It calculates the total salary and rounds the result to 2 decimal places.

d)

It returns the sum of all salaries rounded to 2 decimal places.

15.

Which query returns the first 5 employees in alphabetical order by name?

a)

SELECT * FROM employees ORDER BY name ASC LIMIT 5;

b)

SELECT * FROM employees ORDER BY name LIMIT 5;

c)

SELECT * FROM employees ORDER BY name DESC LIMIT 5;

d)

SELECT * FROM employees LIMIT 5 ORDER BY name ASC;

16.

Which query will return all employees who earn more than the average salary of their respective department?

a)

SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

b)

SELECT * FROM employees e WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id);

c)

SELECT * FROM employees WHERE salary > AVG(salary) GROUP BY department_id;

d)

SELECT * FROM employees WHERE salary > MAX(salary) GROUP BY department_id;

17.

What does the HAVING clause do in a GROUP BY query?

a)

Filters the result before grouping the rows.

b)

Filters the result after grouping the rows.

c)

Joins two tables together.

d)

Defines the column used for grouping.

18.

Which query will return the employees who have never been assigned to a department?

a)

SELECT * FROM employees WHERE department_id IS NULL;

b)

SELECT * FROM employees WHERE department_id = NULL;

c)

SELECT * FROM employees WHERE department_id NOT IN (SELECT department_id FROM departments);

d)

SELECT * FROM employees WHERE department_id = 0;

19.

Which of the following will correctly delete all rows from the employees table?

a)

DELETE FROM employees WHERE 1=1;

b)

REMOVE FROM employees;

c)

TRUNC TABLE employees;

d)

DROP TABLE employees;

e)

No Answer

20.

Which query will return the employees who earn more than 10% of the highest salary in the company?

a)

SELECT FROM employees WHERE salary > (SELECT MAX(salary) FROM employees) 0.1;

b)

SELECT FROM employees WHERE salary > 0.1 (SELECT MAX(salary) FROM employees);

c)

SELECT FROM employees WHERE salary > MAX(salary) 10;

d)

SELECT FROM employees WHERE salary > 10 (SELECT MAX(salary) FROM employees);

21.

What does the following query do?

SELECT DISTINCT employee_id FROM employees WHERE department_id = 1;

a)

It retrieves all employee IDs for department 1, including duplicates.

b)

It retrieves unique employee IDs for department 1

c)

It retrieves all department IDs for department 1

d)

It retrieves all employees with department 1 assigned.

22.

Which query will count the number of rows in the employees table where department_id is not NULL?

a)

SELECT COUNT(*) FROM employees WHERE department_id IS NOT NULL;

b)

SELECT COUNT(department_id) FROM employees;

c)

SELECT COUNT(*) FROM employees WHERE department_id != NULL;

d)

SELECT COUNT(department_id) FROM employees WHERE department_id IS NOT NULL;

23.

Which of the following queries will return the total salary for each department, including departments with zero employees?

a)

SELECT department_id, SUM(salary) FROM employees GROUP BY department_id WITH ROLLUP;

b)

SELECT department_id, SUM(salary) FROM employees GROUP BY department_id;

c)

SELECT department_id, SUM(salary) FROM employees LEFT JOIN departments ON employees.department_id = departments.department_id GROUP BY department_id;

d)

SELECT department_id, SUM(salary) FROM employees LEFT JOIN departments USING (department_id) GROUP BY department_id;

24.

What is the result of the following query?

SELECT * FROM employees LIMIT 10 OFFSET 5;

a)
  • It returns the first 5 rows from the employees table.

b)

It returns rows 1 to 10 from the employees table.

c)
  • It returns rows 6 to 15 from the employees table.

d)

It returns rows 5 to 15 from the employees table.

25.

Which of the following queries can be used to update the salary of employees who belong to department 2 and are under 30 years old?

a)

UPDATE employees SET salary = salary * 1.1 WHERE department_id = 2 AND age < 30;

b)

UPDATE employees SET salary = salary * 1.1 WHERE department_id = 2;

c)

UPDATE employees SET salary = salary + 500 WHERE department_id = 2 AND age < 30;

d)

UPDATE employees SET salary = salary + 500 WHERE department_id = 2 AND age <= 30;

26.

What is the purpose of using DISTINCT in a SELECT statement?

a)
  • To retrieve unique values from a column or combination of columns.

b)

To sort the results in ascending or descending order.

c)

To filter out NULL values from the result set.

d)

To group rows together based on column values.

27.

What does the following SQL query do?

SELECT * FROM employees WHERE name LIKE 'J%n';

a)

Finds employees whose name starts with "J" or contains "n".

b)

Finds employees whose name contains the letter "J" and ends with "n".

c)

Finds employees whose name starts with "J" and contains "n".

d)

Finds employees whose name starts with "J" and ends with "n".

28.

Which statement is used to change the structure of an existing table in MySQL?

a)

ALTER TABLE

b)

MODIFY TABLE

c)

UPDATE TABLE

d)

CHANGE STRUCTURE

29.

Which query will return the department with the highest total salary expenditure?

a)

SELECT department_id, SUM(salary) AS total_salary FROM employees GROUP BY department_id ORDER BY total_salary DESC LIMIT 1;

b)

SELECT department_id, MAX(SUM(salary)) FROM employees GROUP BY department_id;

c)

SELECT department_id, SUM(salary) FROM employees ORDER BY salary DESC LIMIT 1;

d)

SELECT department_id, COUNT(salary) FROM employees GROUP BY department_id ORDER BY salary DESC LIMIT 1;

30.

What does the following query do?

SELECT COUNT(DISTINCT department_id) FROM employees;

a)

It counts the total number of distinct department IDs.

b)

It counts all rows in the employees table.

c)

It counts the number of departments in the employees table.

d)
  • It counts employees who belong to more than one department.

31.

Which of the following SQL statements is used to add a new column to an existing table?

a)

INSERT COLUMN INTO employees (birthdate DATE);

b)

CREATE COLUMN TABLE employees (birthdate DATE);

c)

CREATE COLUMN TABLE employees (birthdate DATE);

d)

ALTER TABLE employees ADD COLUMN birthdate DATE;

32.

What does the following query do?

SELECT employee_id, salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = 2);

a)

It returns employees with a salary less than the average salary in department 2.

b)

It returns employees with the highest salary in department 2.

c)
  • It returns employees who earn the average salary in department 2.

d)

It returns employees with a salary greater than the average salary of all employees in department 2.

33.

What does the IS NULL condition do in SQL?

a)

Checks if a column contains the string "NULL".

b)

Checks if a column contains an empty string.

c)

Checks if a column contains a NULL value.

d)

Checks if a column contains the value 0.

34.

Which of the following SQL queries can be used to update the salary of employees in department 1, adding a 10% increase for employees who have worked for more than 5 years?

a)

UPDATE employees SET salary = salary * 1.1 WHERE department_id = 1;

b)

UPDATE employees SET salary = salary + salary * 0.1 WHERE department_id = 1 AND years_of_service > 5;

c)

UPDATE employees SET salary = salary * 1.1 WHERE department_id = 1 AND years_of_service > 5;

d)

UPDATE employees SET salary = salary + 0.1 WHERE department_id = 1 AND years_of_service > 5;

35.

Which query will return the second highest salary from the employees table?

a)

SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);

b)

SELECT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;

c)

SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 2,1;

d)

SELECT salary FROM employees ORDER BY salary DESC LIMIT 2;

36.

What is the correct query to retrieve the first name and last name of employees who earn above the average salary in their respective departments?

a)

SELECT first_name, last_name FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

b)

SELECT first_name, last_name FROM employees e WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id);

c)

SELECT first_name, last_name FROM employees WHERE salary > AVG(salary) GROUP BY department_id;

d)

SELECT first_name, last_name FROM employees WHERE salary > MAX(salary) GROUP BY department_id;

37.

Which of the following statements is true about foreign keys in MySQL?

a)

Foreign keys can reference columns with a non-unique index

b)

Foreign keys can reference columns with a UNIQUE or PRIMARY key.

c)

Foreign keys cannot be defined on columns with NULL values

d)

Foreign keys automatically create an index on the referenced column

38.

Which of the following queries will return employees who belong to the same department as "John Doe"?

a)

SELECT * FROM employees WHERE department_id = 'John Doe';

b)

SELECT * FROM employees WHERE department_id = (SELECT department_id FROM employees WHERE first_name = 'John' AND last_name = 'Doe') LIMIT 5;

c)

SELECT * FROM employees WHERE department_id = (SELECT department_id FROM employees WHERE first_name = 'John' AND last_name = 'Doe') LIMIT 5;

d)

SELECT * FROM employees WHERE department_id = (SELECT department_id FROM employees WHERE first_name = 'John' AND last_name = 'Doe');

39.

Which query will return the employees who have the same salary as the highest salary in the company?

a)

SELECT * FROM employees WHERE salary = MAX(salary);

b)

SELECT * FROM employees WHERE salary = (SELECT MAX(salary) FROM employees);

c)

SELECT * FROM employees WHERE salary = (SELECT AVG(salary) FROM employees);

d)

SELECT * FROM employees WHERE salary > (SELECT MAX(salary) FROM employees);

40.

Which of the following queries will find all employees who were hired in the year 2022?

a)

SELECT * FROM employees WHERE hire_date BETWEEN '2022-01-01' AND '2022-12-31';

b)

SELECT * FROM employees WHERE YEAR(hire_date) = 2022;

c)

SELECT * FROM employees WHERE hire_date LIKE '2022%';

d)

SELECT * FROM employees WHERE hire_date = '2022';

41.

Which query will return the department with the lowest average salary?

a)

SELECT department_id, MIN(salary) FROM employees GROUP BY department_id ORDER BY MIN(salary) ASC LIMIT 1;

b)

SELECT department_id, AVG(salary) FROM employees ORDER BY AVG(salary) DESC LIMIT 1;

c)

SELECT department_id, MAX(salary) FROM employees GROUP BY department_id ORDER BY MAX(salary) ASC LIMIT 1;

d)

SELECT department_id, AVG(salary) FROM employees GROUP BY department_id ORDER BY AVG(salary) ASC LIMIT 1;

42.

Which SQL statement is used to add a new row to an existing table?

(a)  

43.

What does the following query do?

SELECT employee_id, salary FROM employees WHERE department_id = 3 ORDER BY salary LIMIT 5;

a)

It returns the top 5 highest paid employees from department 3.

b)

It returns the lowest 5 paid employees from department 3.

c)

It returns all employees from department 3 with their salaries, ordered by salary, limited to 5 rows.

d)

It returns the employees with salaries greater than 5 from department 3.

44.

Which query will return the number of employees who earn above the average salary?

a)

SELECT COUNT(salary) FROM employees WHERE salary > AVG(salary);

b)

SELECT COUNT(*) FROM employees WHERE salary > AVG(salary);

c)

SELECT COUNT(*) FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

d)

SELECT COUNT(salary) FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

45.

Which query will return employees who have been working for more than 10 years and belong to department 2?

a)

SELECT * FROM employees WHERE years_of_service > 10 OR department_id = 2;

b)

SELECT * FROM employees WHERE years_of_service > 10 AND department_id = 2;

c)

SELECT * FROM employees WHERE years_of_service > 10 AND department_id = '2';

d)

SELECT * FROM employees WHERE years_of_service > 10 OR department_id = '2';

46.

Which of the following SQL queries will return the first three records from the employees table ordered by salary in descending order?

a)

SELECT * FROM employees LIMIT 3 ORDER BY salary;

b)

SELECT * FROM employees LIMIT 3 ORDER BY salary DESC;

c)

SELECT * FROM employees ORDER BY salary DESC LIMIT 3;

d)

SELECT * FROM employees ORDER BY salary LIMIT 3;

47.

Which query will return employees who do not have a manager (i.e., employees who have NULL in the manager_id column)?

a)

SELECT * FROM employees WHERE manager_id = NULL;

b)

SELECT * FROM employees WHERE manager_id != NULL;

c)

SELECT * FROM employees WHERE manager_id = 'NULL';

d)

SELECT * FROM employees WHERE manager_id IS NULL;

48.

What is the result of the following query?

SELECT AVG(salary) FROM employees WHERE salary > 50000;

a)

It returns the average salary of all employees.

b)

It returns the average salary of employees earning more than 50,000.

c)

It returns the total salary of employees earning more than 50,000

d)

It returns the highest salary among employees earning more than 50,000

49.

Which query will return a list of departments that have more than 5 employees?

a)

SELECT department_id FROM employees HAVING COUNT(employee_id) > 5 GROUP BY department_id;

b)

SELECT department_id FROM employees GROUP BY department_id HAVING COUNT(*) > 5;

c)

SELECT department_id FROM employees GROUP BY department_id HAVING COUNT(employee_id) > 5;

d)

SELECT department_id FROM employees WHERE COUNT(employee_id) > 5 GROUP BY department_id;

50.

Which query will return the number of distinct departments in which employees work?

a)

SELECT COUNT(department_id) FROM employees;

b)

SELECT DISTINCT COUNT(department_id) FROM employees;

c)

SELECT COUNT(DISTINCT department_id) FROM employees;

d)

SELECT DISTINCT department_id FROM employees;

51.

Which query will remove duplicate rows from the result of a query?

a)

DELETE FROM table WHERE column1 = column2;

b)

SELECT DISTINCT column1, column2 FROM table;

c)

SELECT column1, column2 FROM table WHERE DISTINCT;

d)

SELECT UNIQUE column1, column2 FROM table;

52.

Which query will return the total number of employees in each department, along with the department ID?

a)

SELECT COUNT(*) FROM employees GROUP BY department_id;

b)

SELECT department_id, COUNT(employee_id) FROM employees;

c)

SELECT department_id, COUNT(employee_id) FROM employees GROUP BY department_id;

d)

SELECT department_id, COUNT(*) FROM employees GROUP BY department_id;

53.

Which of the following queries will return all employees who were hired after the first of January, 2020?

a)

SELECT * FROM employees WHERE hire_date > '2020-01-01' AND hire_date < NOW();

b)

SELECT * FROM employees WHERE hire_date >= '2020-01-01';

c)

SELECT * FROM employees WHERE hire_date < '2020-01-01';

d)

SELECT * FROM employees WHERE hire_date > '2020-01-01';

54.

Which query will return the highest salary in each department, excluding departments where the highest salary is less than 50,000?

a)

SELECT department_id, MAX(salary) FROM employees HAVING salary > 50000 GROUP BY department_id;

b)

SELECT department_id, MAX(salary) FROM employees GROUP BY department_id HAVING MAX(salary) >= 50000;

c)

SELECT department_id, MAX(salary) FROM employees GROUP BY department_id HAVING MAX(salary) > 50000;

d)

SELECT department_id, MAX(salary) FROM employees WHERE salary >= 50000 GROUP BY department_id;

55.

Which query will update the email address of the employee with employee_id = 10?

a)

UPDATE employees SET email = 'new_email@example.com' WHERE employee_id = '10';

b)

UPDATE employees SET email = 'new_email@example.com' WHERE id = 10;

c)

MODIFY employees SET email = 'new_email@example.com' WHERE employee_id = 10;

d)

UPDATE employees SET email = 'new_email@example.com' WHERE employee_id = 10;

56.

Which query will return the second highest salary in the employees table?

a)

SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);

b)

SELECT salary FROM employees WHERE salary > (SELECT MAX(salary) FROM employees LIMIT 1 OFFSET 1);

c)

SELECT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;

d)

SELECT salary FROM employees ORDER BY salary LIMIT 1,1;

57.

What does the following query do?

SELECT COUNT(*) FROM employees WHERE hire_date BETWEEN '2020-01-01' AND '2020-12-31';

a)

It counts the number of employees hired after January 1st, 2020

b)

It counts the number of employees hired between January 1st and December 31st, 2020

c)

It counts the total number of employees hired in 2020

d)

It counts the number of employees hired before December 31st, 2020

58.

Which query will update the salary of all employees by increasing it by 10%?

a)

UPDATE employees SET salary = salary + 0.10;

b)

UPDATE employees SET salary = salary * 1.10;

c)

UPDATE employees SET salary = salary * 10;

d)

UPDATE employees SET salary = salary + 10;

59.

What will the following query do?

SELECT DISTINCT department_id FROM employees WHERE department_id IS NOT NULL;

a)

It will return all departments that have at least one employee.

b)

It will return departments that have employees with a NULL department_id.

c)

It will return departments where the department_id is not NULL.

d)

It will return the total count of non-NULL department IDs.

60.

Which of the following queries is used to find duplicate rows based on a specific column (e.g., email)?

a)

SELECT email FROM employees GROUP BY email HAVING COUNT(email) > 1;

b)

SELECT DISTINCT email FROM employees;

c)

SELECT email FROM employees WHERE COUNT(email) > 1;

d)

SELECT email FROM employees HAVING COUNT(email) > 1;

61.

Which query will create a new table temp_employees with the same structure as employees?

a)

CREATE TABLE temp_employees AS SELECT * FROM employees WHERE 1=0;

b)

CREATE TABLE temp_employees LIKE employees;

c)

CREATE TABLE temp_employees SELECT * FROM employees;

d)

CREATE TABLE temp_employees AS SELECT * FROM employees;

62.

Which query will return the total number of orders placed by each customer in the orders table?

a)

SELECT customer_id, COUNT(order_id) FROM orders GROUP BY customer_id;

b)

SELECT customer_id, COUNT(order_id) FROM orders;

c)

SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id;

d)

SELECT customer_id, SUM(order_id) FROM orders GROUP BY customer_id;

63.

Which of the following queries will return employees who have not been assigned to any project (assuming the projects table contains a project_id and employee_id)?

a)

SELECT * FROM employees WHERE employee_id NOT LIKE (SELECT employee_id FROM projects);

b)

SELECT * FROM employees WHERE employee_id NOT IN (SELECT DISTINCT employee_id FROM projects);

c)

SELECT * FROM employees WHERE employee_id NOT EXISTS (SELECT employee_id FROM projects);

d)

SELECT * FROM employees WHERE employee_id NOT IN (SELECT employee_id FROM projects);

64.

Which query will return the total salary for each department, excluding departments where the total salary is less than 100,000?

a)

SELECT department_id, SUM(salary) FROM employees GROUP BY department_id HAVING SUM(salary) > 100000;

b)

SELECT department_id, SUM(salary) FROM employees WHERE SUM(salary) >= 100000 GROUP BY department_id;

c)

SELECT department_id, SUM(salary) FROM employees HAVING SUM(salary) >= 100000 GROUP BY department_id;

d)

SELECT department_id, SUM(salary) FROM employees GROUP BY department_id HAVING SUM(salary) >= 100000;

65.

What is the correct query to remove a column named age from the employees table?

a)

DROP COLUMN age FROM employees;

b)

REMOVE COLUMN age FROM employees;

c)

ALTER TABLE employees DROP COLUMN age;

d)

DELETE COLUMN age FROM employees;

66.

Which query will return the average salary of employees in each department, excluding departments where the average salary is less than 40,000?

a)

SELECT department_id, AVG(salary) FROM employees HAVING AVG(salary) >= 40000 GROUP BY department_id;

b)

SELECT department_id, AVG(salary) FROM employees WHERE AVG(salary) >= 40000 GROUP BY department_id;

c)

SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING AVG(salary) >= 40000;

d)

SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING AVG(salary) > 40000;

67.

Which query will return the number of orders for each customer, only for customers who have placed more than 10 orders?

a)

SELECT customer_id, COUNT(*) FROM orders WHERE COUNT(*) > 10 GROUP BY customer_id;

b)

SELECT customer_id, COUNT(order_id) FROM orders WHERE COUNT(order_id) > 10 GROUP BY customer_id;

c)

SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id HAVING COUNT(*) > 10;

d)

SELECT customer_id, COUNT(order_id) FROM orders GROUP BY customer_id HAVING COUNT(order_id) > 10;

68.

Which of the following queries will find employees who are not assigned to any department (i.e., have a NULL department_id)?

a)

SELECT * FROM employees WHERE department_id NOT NULL;

b)

SELECT * FROM employees WHERE department_id IS NULL;

c)

SELECT * FROM employees WHERE department_id = 'NULL';

d)

SELECT * FROM employees WHERE department_id = NULL;

69.

Which query will return all the employees who have a salary greater than the average salary in their department?

a)

SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees GROUP BY department_id);

b)

SELECT * FROM employees WHERE salary > AVG(salary);

c)

SELECT * FROM employees WHERE salary > AVG(salary) GROUP BY department_id;

d)

SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = employees.department_id);

70.

Which query will return the employee with the lowest salary in each department?

a)

SELECT department_id, salary FROM employees HAVING salary = MIN(salary);

b)

SELECT department_id, MIN(salary) FROM employees ORDER BY department_id;

c)

SELECT department_id, salary FROM employees WHERE salary = (SELECT MIN(salary) FROM employees WHERE department_id = employees.department_id);

d)

SELECT department_id, MIN(salary) FROM employees GROUP BY department_id;

71.

Which query will return the top 3 most expensive products from the products table, ordered by price in descending order?

a)

SELECT * FROM products ORDER BY price ASC LIMIT 3;

b)

SELECT * FROM products ORDER BY price DESC LIMIT 3 OFFSET 3;

c)

SELECT * FROM products LIMIT 3 ORDER BY price DESC;

d)

SELECT * FROM products ORDER BY price DESC LIMIT 3;

72.

Which query will return the employees who have the highest salary in each department?

a)

SELECT department_id, salary FROM employees HAVING salary = MAX(salary);

b)

SELECT department_id, MAX(salary) FROM employees GROUP BY department_id;

c)

SELECT department_id, salary FROM employees WHERE salary = (SELECT MAX(salary) FROM employees WHERE department_id = employees.department_id);

d)

SELECT department_id, salary FROM employees GROUP BY department_id ORDER BY salary DESC LIMIT 1;

73.

Which query will return the average salary of employees for each department, but only include departments with more than 5 employees?

a)

SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING COUNT(employee_id) > 5;

b)

SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING COUNT(*) > 5;

c)

SELECT department_id, AVG(salary) FROM employees WHERE COUNT(employee_id) > 5 GROUP BY department_id;

d)

SELECT department_id, AVG(salary) FROM employees HAVING COUNT(employee_id) > 5 GROUP BY department_id;

74.

Which of the following queries will find employees who have the same salary?

a)

SELECT employee_id, salary FROM employees WHERE salary IN (SELECT salary FROM employees GROUP BY salary HAVING COUNT(salary) > 1);

b)

SELECT employee_id, salary FROM employees GROUP BY salary HAVING COUNT(salary) > 1;

c)

SELECT employee_id, salary FROM employees WHERE salary IN (SELECT salary FROM employees HAVING COUNT(salary) > 1);

d)

SELECT employee_id, salary FROM employees WHERE salary = (SELECT salary FROM employees HAVING COUNT(salary) > 1);

75.

Which query will find the employees who have the same last name as any employee from the employees table but with a different employee_id?

a)

SELECT * FROM employees WHERE last_name IN (SELECT last_name FROM employees WHERE employee_id != 1);

b)

SELECT * FROM employees WHERE last_name IN (SELECT last_name FROM employees WHERE employee_id = employees.employee_id);

c)

SELECT * FROM employees WHERE last_name = (SELECT last_name FROM employees WHERE employee_id != employees.employee_id);

d)

SELECT * FROM employees WHERE last_name IN (SELECT last_name FROM employees WHERE employee_id != employees.employee_id);