Text preview & study summary

SQL Database Fundamentals

A free sample of 5 questions from this quiz, shown in full with answer choices and explanations. No interactivity — everything is visible on this page for study and review.

Want to test your knowledge? Launch the Interactive Exam Simulator

Question 1

What type of JOIN returns only rows where there is a match in BOTH tables?

Answer choices

  • A. LEFT JOIN

  • B. RIGHT JOIN

  • C. FULL OUTER JOIN

  • D. INNER JOIN (Correct)

Explanation

INNER JOIN returns only rows where the join condition is met in BOTH tables (the intersection). LEFT JOIN returns all rows from the left table plus matching rows from the right (unmatched right rows are NULL). RIGHT JOIN is the mirror opposite. FULL OUTER JOIN returns all rows from both tables, with NULLs where there is no match.

Question 2

What does the following query do?

```sql

SELECT department, COUNT(*) as employee_count

FROM employees

GROUP BY department

HAVING COUNT(*) > 5;

```

Answer choices

  • A. Selects all employees in departments with more than 5 total employees in the company

  • B. Counts employees per department and shows only departments that have more than 5 employees (Correct)

  • C. Deletes departments with fewer than 5 employees

  • D. Selects the top 5 employees from each department

Explanation

`GROUP BY department` aggregates rows by department. `COUNT(*)` counts rows in each group. `HAVING COUNT(*) > 5` filters the groups, keeping only those with more than 5 employees. Remember: `WHERE` filters individual rows before grouping; `HAVING` filters groups after aggregation.

Question 3

Place the SQL clauses in the correct logical execution order (the order the database engine processes them, not how they appear in the query):

Answer choices

  • A. ORDER BY

  • B. FROM / JOIN

  • C. HAVING

  • D. SELECT

  • E. WHERE

Explanation

SQL executes in this logical order: FROM (identify tables/joins), WHERE (filter rows), GROUP BY (aggregate), HAVING (filter groups), SELECT (compute columns), ORDER BY (sort). This explains why you can't use a SELECT alias in a WHERE clause (alias isn't created yet) but CAN use it in ORDER BY. It also explains why HAVING comes after GROUP BY.

Question 4

Which of the following are SQL aggregate functions? (Select ALL that apply)

Answer choices

  • A. COUNT() (Correct)

  • B. SUM() (Correct)

  • C. AVG() (Correct)

  • D. CONCAT()

  • E. MAX() (Correct)

Explanation

Aggregate functions operate on a set of rows and return a single value: COUNT() counts rows, SUM() adds values, AVG() calculates average, MAX() finds the maximum (MIN() finds the minimum). CONCAT() is a string function that joins strings together. TRIM() removes leading/trailing spaces — also a string function, not an aggregate.

Question 5

What does the SQL `DISTINCT` keyword do?

Answer choices

  • A. Sorts results in descending order

  • B. Removes duplicate rows from the result set (Correct)

  • C. Returns only the first distinct column

  • D. Filters NULL values from results

Explanation

`SELECT DISTINCT column FROM table` eliminates duplicate values in the result. Example: if a table has 100 order rows but only 10 unique customers, `SELECT DISTINCT customer_id FROM orders` returns 10 rows. It evaluates uniqueness across ALL selected columns when multiple columns are selected.