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?
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;
```
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):
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)
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?
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.
