Data and Analytics SQL and Database Fundamentals 1 — Questions and Answers
Question 1: Which SQL clause is used to filter rows after aggregation?
- WHERE
- HAVING (Correct answer)
- GROUP BY
- ORDER BY
Correct answer: HAVING
HAVING filters groups created by GROUP BY, whereas WHERE filters individual rows before aggregation.
Question 2: What does a PRIMARY KEY constraint enforce in a relational database?
- Referential integrity
- Unique, non-null values per row (Correct answer)
- Default column values
- Column data types
Correct answer: Unique, non-null values per row
A PRIMARY KEY ensures every row has a unique, non-null identifier in that column or set of columns.
Question 3: Which SQL JOIN returns only rows where there is a match in both tables?
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN
- INNER JOIN (Correct answer)
Correct answer: INNER JOIN
INNER JOIN returns only the rows that have matching values in both joined tables.
Question 4: What is the purpose of an index in a relational database?
- To enforce referential integrity
- To speed up data retrieval queries (Correct answer)
- To normalize table structure
- To encrypt stored data
Correct answer: To speed up data retrieval queries
An index creates a data structure that allows the database engine to find rows faster without scanning the entire table.
Question 5: Which normal form eliminates transitive dependencies?
- 1NF
- 2NF
- 3NF (Correct answer)
- BCNF
Correct answer: 3NF
Third Normal Form (3NF) removes transitive dependencies, ensuring non-key columns depend only on the primary key.
Question 6: What does the SQL DISTINCT keyword do?
- Sorts results alphabetically
- Removes duplicate rows from the result set (Correct answer)
- Filters NULL values
- Limits the number of rows returned
Correct answer: Removes duplicate rows from the result set
DISTINCT eliminates duplicate rows from the query result, returning only unique value combinations.
Which SQL clause is used to filter rows after aggregation?