Google Cloud Professional Cloud Developer — Question 20
You have two tables in an ANSI-SQL compliant database with identical columns that you need to quickly combine into a single table, removing duplicate rows from the result set.
What should you do?
Answer options
- A. Use the JOIN operator in SQL to combine the tables.
- B. Use nested WITH statements to combine the tables.
- C. Use the UNION operator in SQL to combine the tables.
- D. Use the UNION ALL operator in SQL to combine the tables.
Correct answer: C
Explanation
The UNION operator in SQL combines the results of two or more SELECT statements and automatically removes duplicate rows from the result set, which is exactly what is needed in this scenario. The JOIN operator connects tables but does not eliminate duplicates, while UNION ALL includes all records, duplicates included. Nested WITH statements do not inherently remove duplicates and are not necessary for this task.