SQL General Concepts 3 — Questions and Answers
Question 1: Which type of JOIN returns only rows with matching values in both tables?
- INNER JOIN (Correct answer)
- LEFT JOIN
- FULL OUTER JOIN
- CROSS JOIN
Correct answer: INNER JOIN
An INNER JOIN returns only rows where the join condition matches in both tables.
Question 2: What does a foreign key establish?
- A link between two tables (Correct answer)
- A unique index
- Automatic sorting
- A stored procedure
Correct answer: A link between two tables
A foreign key references a primary key in another table, enforcing referential integrity.
Question 3: Which aggregate function counts the number of rows?
- COUNT() (Correct answer)
- SUM()
- AVG()
- MAX()
Correct answer: COUNT()
COUNT() returns the number of rows matching the query.
Question 4: What does the GROUP BY clause do?
- Groups rows sharing a value for aggregation (Correct answer)
- Sorts the result set
- Filters individual rows
- Joins two tables
Correct answer: Groups rows sharing a value for aggregation
GROUP BY groups rows with the same values so aggregate functions can summarize them.
Question 5: Which clause filters results after aggregation?
- HAVING (Correct answer)
- WHERE
- ORDER BY
- LIMIT
Correct answer: HAVING
HAVING filters groups after aggregation, unlike WHERE which filters rows before.
Question 6: What is the purpose of an index in a database?
- To speed up data retrieval (Correct answer)
- To encrypt data
- To delete duplicates
- To back up tables
Correct answer: To speed up data retrieval
An index improves query performance by allowing faster lookups.
Question 7: Which keyword removes duplicate rows from a result set?
- DISTINCT (Correct answer)
- UNIQUE
- DIFFERENT
- SINGLE
Correct answer: DISTINCT
DISTINCT eliminates duplicate rows from the query output.
Which type of JOIN returns only rows with matching values in both tables?