DA0-002 practice question 15 of 25

[Data Acquisition and Preparation]A data analyst needs to create a combined report that includes information from the following two tables: Managers…

Full set: 111 questions

[Data Acquisition and Preparation]

A data analyst needs to create a combined report that includes information from the following two tables: Managers table ID First_name Last_name Job_title 1001 John Doe Manager 1002 Jane Roe Director Non-managers table ID First_name Last_name Job_title 1003 Robert Roe Business Analyst 1004 Jane Doe Sales Representative 1005 John Roe Operations Analyst Which of the following query methods should the analyst use for this task?

Answer options
A: Group
B: Join
C: Union Correct answer
D: Nested
Correct Answer:
C. Union
Explanation

The UNION operator in SQL is used to combine the result sets of two or more SELECT statements into a single result set. It appends the rows from one table to another. For this operation to work, the tables must have the same number of columns, and the corresponding columns must have compatible data types. In this scenario, both the Managers and Non-managers tables share an identical structure, making UNION the correct method to create a single, consolidated report of all employees by stacking the rows from both tables vertically.

Why Incorrect

A. Group: This is used with aggregate functions (e.g., COUNT, SUM) to summarize data into groups, not to combine tables.
B. Join: This combines tables horizontally based on a related column, merging columns from multiple tables into a single row.
D. Nested: This refers to a subquery (a query within another query) and describes a query's structure, not the specific operation for combining these tables.

References

1. Microsoft SQL Server Documentation. (2023). UNION (Transact-SQL). Microsoft Docs. In the "Arguments" section, it is stated that UNION "Specifies that multiple result sets are to be combined and returned as a single result set." The basic example shows combining two tables with identical column structures.

2. PostgreSQL 16 Documentation. (2023). 7.4. Combining Queries. In this section, the documentation states, "The UNION operator computes the set union of the rows returned by the involved SELECT statements... The two SELECT statements that represent the direct operands of the UNION must produce the same number of columns, and corresponding columns must be of compatible data types."

3. Ullman, J. D., & Widom, J. (n.d.). CS145 Introduction to Databases Course Notes: More SQL. Stanford University. In the section on "Union, Intersection, and Difference of Relations," the notes specify that UNION is the standard set-union operator for SQL, requiring the tables to be "union-compatible," which the tables in the question are.

Scroll to Top