DAC DAC Database & SQL Analytics 1 — Questions and Answers
Question 1: Which SQL clause is used to filter rows after aggregation has been performed?
- WHERE
- GROUP BY
- HAVING (Correct answer)
- ORDER BY
Correct answer: HAVING
The HAVING clause filters groups after aggregation (e.g., after GROUP BY), while WHERE filters individual rows before aggregation.
Question 2: What is the difference between an INNER JOIN and a LEFT JOIN in SQL?
- INNER JOIN returns all rows from both tables; LEFT JOIN returns only matching rows
- INNER JOIN returns only matching rows; LEFT JOIN returns all rows from the left table plus matching rows from the right (Correct answer)
- LEFT JOIN always returns fewer rows than INNER JOIN
- There is no functional difference between the two
Correct answer: INNER JOIN returns only matching rows; LEFT JOIN returns all rows from the left table plus matching rows from the right
INNER JOIN returns only rows with matching values in both tables, while LEFT JOIN returns all rows from the left table and matching rows from the right (NULLs for non-matches).
Question 3: Which SQL aggregate function returns the number of non-NULL values in a column?
- SUM()
- MAX()
- COUNT() (Correct answer)
- AVG()
Correct answer: COUNT()
COUNT() counts non-NULL values when given a column name, or all rows (including NULLs) when used as COUNT(*).
Question 4: What does a database index primarily improve?
- Data insertion speed
- Data query and retrieval speed (Correct answer)
- Data storage compression
- Data encryption overhead
Correct answer: Data query and retrieval speed
Database indexes speed up SELECT queries by allowing the database engine to find rows quickly without scanning the entire table.
Question 5: In SQL, what does the DISTINCT keyword do?
- Sorts results in ascending order
- Filters rows based on a condition
- Removes duplicate values from the result set (Correct answer)
- Joins two tables together
Correct answer: Removes duplicate values from the result set
DISTINCT eliminates duplicate rows from a query result, returning only unique values for the selected columns.
Question 6: What is a primary key in a relational database?
- A key used for encrypting sensitive data
- A column or combination of columns that uniquely identifies each row in a table (Correct answer)
- The first column in every table by convention
- A foreign key that references another table
Correct answer: A column or combination of columns that uniquely identifies each row in a table
A primary key uniquely identifies each record in a table and cannot contain NULL values, ensuring data integrity.
Which SQL clause is used to filter rows after aggregation has been performed?