wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Dive in SQL

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

Which SQL keyword is used to retrieve only unique values from a column?

a)

DISTINCT

b)

UNIQUE

c)

LIMIT

d)

GROUP BY

2.

What does the INNER JOIN operation return?

a)

a) All rows from the left table

b)

All rows from the right table

c)

Rows that have matching values in both tables

d)

Non-matching rows from both tables

3.

Given the following SQL query, what will be the result of the subquery?

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

a)

All employees with salaries less than the average

b)

All employees with salaries greater than the average

c)

An error

4.

Which command is used to remove all rows from a table but keep the structure intact?

a)

DELETE

b)

DROP

c)

TRUNCATE

d)

REMOVE

5.

Which of the following SQL clauses is used to specify the conditions under which a group is included in the result set of a GROUP BY statement?

(a)  

6.

What is the effect of using RANK() in a SQL query as opposed to ROW_NUMBER()?

a)

RANK() skips ranks when there are ties, while ROW_NUMBER() does not.

b)

ROW_NUMBER() skips ranks when there are ties, while RANK() does not.

c)

Both RANK() and ROW_NUMBER() produce identical results.

d)

RANK() and ROW_NUMBER() can be used interchangeably without any difference.

7.

Which of the following SQL queries would return duplicate rows in its result set?

a)

SELECT * FROM products;

b)

SELECT DISTINCT * FROM products;

c)

SELECT product_id, COUNT(*)

FROM products

GROUP BY product_id;

d)

SELECT * FROM products GROUP BY product_id;

8.

Which query returns the total sales amount for each product but includes only products where the total sales exceed $1000?

a)

SELECT product_id, COUNT(amount)

FROM sales

GROUP BY product_id

HAVING COUNT(amount) > 1000;

b)

SELECT product_id, SUM(amount)

FROM sales

WHERE SUM(amount) > 1000

GROUP BY product_id;

c)

SELECT product_id, SUM(amount)

FROM sales

GROUP BY product_id

HAVING SUM(amount) > 1000;

d)

SELECT product_id, SUM(amount)

FROM sales

GROUP BY product_id

WHERE SUM(amount) > 1000;

9.

What is the purpose of a window function in SQL?

a)

To perform row-level operations.

b)

To apply aggregate functions over a specified range of rows.

c)

To calculate the number of rows in a table.

d)

To delete rows in a partitioned query.

10.

Which SQL 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 MAX(salary)

FROM employees

ORDER BY salary DESC

LIMIT 1, 1;

c)

SELECT salary

FROM employees

ORDER BY salary DESC

LIMIT 1 OFFSET 1;

d)

SELECT salary

FROM employees

WHERE salary < MAX(salary);

11.

Which SQL statement is used to remove duplicate records from a result set?

a)

SELECT DISTINCT

b)

SELECT UNIQUE

c)

SELECT ALL

d)

SELECT GROUP BY

12.

What is the result of using the COUNT() function in a SQL query?

a)

It returns the total number of rows in a table.

b)

It returns the number of distinct values in a column.

c)

It returns the sum of a numeric column.

d)

It returns the average of a numeric column.

13.

Which SQL statement is used to update existing records in a table?

a)

UPDATE

b)

MODIFY

c)

SET

d)

CHANGE

14.

Which SQL function is used to calculate the average value of a numeric column?

a)

SUM()

b)

AVG()

c)

COUNT()

d)

MEDIAN()

15.

What is the purpose of the GROUP BY clause in SQL?

a)

To filter records based on a condition

b)

To aggregate data across multiple rows

c)

To sort the result set

d)

To join two tables

16.

Which SQL statement is used to create a new table in a database?

a)

CREATE TABLE

b)

NEW TABLE

c)

ADD TABLE

d)

INSERT TABLE

17.

What is the function of the ORDER BY clause in SQL?

a)

To filter records based on a condition

b)

To sort the result set in a specified order

c)

To group records with similar values

d)

To limit the number of records returned

18.

Which SQL statement is used to remove a table from a database?

a)

DELETE TABLE

b)

DROP TABLE

c)

REMOVE TABLE

d)

ALTER TABLE

19.

What does the COALESCE() function do in SQL?

a)

It returns the first non-null value in a list of arguments.

b)

It counts the number of non-null values in a column.

c)

It concatenates two or more strings.

d)

It converts a value to a specified data type.

20.

What is the purpose of the JOIN operation in SQL?

a)

To combine rows from two or more tables based on a related column.

b)

To filter records based on a specific condition.

c)

To create a new table from existing tables.

d)

To delete records from a table.