SQL Questions and Answers – SQL Union

This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Union”.

1. Which operator is used to combine the result-set of two or more SELECT statements?
a) Combine
b) Merge
c) Union
d) Join
View Answer

Answer: c
Explanation: The UNION operator is used to combine the result-sets of two or more SELECT queries into a single result set removing the duplicate rows.

2. By default, the UNION operator selects ______
a) Only duplicate values
b) Only distinct values
c) Only null values
d) All values
View Answer

Answer: b
Explanation: The UNION operator is used to combine the result-set of two or more SELECT statements. By default it selects only distinct values.

3. How many result-sets can be combined using UNION operator?
a) Two
b) One
c) Two or more
d) Three or more
View Answer

Answer: c
Explanation: The SQL UNION operator is used to combine the results of two or more SELECT statements without returning any duplicate rows.
advertisement
advertisement

4. Each SELECT statement within UNION can have any number of columns.
a) True
b) False
View Answer

Answer: b
Explanation: The number of the columns must be the same in all SELECT statements whose result-sets are to be combined using UNION operator.

5. The columns in each SELECT statement with UNION operator should be in ____________
a) Random order
b) Reverse order
c) Same order
d) Numeric data type
View Answer

Answer: c
Explanation: The order of the columns must be the same in all SELECT statements with UNION operator between them.

6. Data types of the corresponding columns of SELECT statements with UNION operator _______
a) Must be different
b) Must be similar
c) Can be similar or different
d) Should not belong to date data type
View Answer

Answer: b
Explanation: The columns listed in the SELECT statements with UNION operator must have similar data types. Those columns can also have date data type.

7. Which of the following conditions are required to make a set of SELECT statements as union-compatible?
a) Columns must be in same order, same number and same data type
b) Columns must be in same order, any number and same data type
c) Columns must be in any order, same number and same data type
d) Columns must be in same order and same number
View Answer

Answer: a
Explanation: A set of SELECT statements are said to be union-compatible only when the fields used in those statements are in same order, same number and same data type.
advertisement

8. To fetch duplicate values along with the distinct values while combining the result-sets of two or more tables, which operator is used?
a) Union
b) All
c) Union All
d) Union Duplicates
View Answer

Answer: c
Explanation: The UNION operation eliminates the duplicate rows from the combined result set, by default. To fetch the duplicate values too UNION ALL must be used in the place of UNION.

9. Column names must be same in the SELECT statements with UNION operator.
a) True
b) False
View Answer

Answer: b
Explanation: Column names in the SELECT statements with UNION operator can be different but their data types must be same.
advertisement

10. Column names in the resultset of a UNION are ______
a) The column names of the first SELECT statement
b) The column names of the last SELECT statement
c) The combination of column names of first and last SELECT statements
d) The column names of any of the SELECT statements
View Answer

Answer: a
Explanation: The column names in the result-set are usually the column names in the first SELECT statement of the UNION.

11. What is the basic syntax used in SQL to combine the result-set of two tables?
a) Select column_list From table1 Select column_list From table2 UNION;
b) Select column_list From table1 UNION Select column_list From table2;
c) Select column_list UNION Select column_list From table1;
d) Select column_list From table1 COMBINE Select column_list From table2;
View Answer

Answer: b
Explanation: To combine the result-sets of two or more tables, UNION operator is used. Basic syntax of a UNION operator is:

SELECT column_list FROM table1 UNION SELECT column_list FROM table2;

12. What is the basic syntax of a UNION ALL operator?
a) Select column_list From table1 Select column_list From table2 UNION ALL;
b) Select column_list UNION ALL Select column_list From table1;
c) Select column_list From table1 ALL Select column_list From table2;
d) Select column_list From table1 UNION ALL Select column_list From table2;
View Answer

Answer: d
Explanation: The UNION ALL operator is used to combine the results of two or more SELECT statements including duplicate rows. Basic syntax of a UNION ALL operator is:

SELECT column_list FROM table1 UNION ALL SELECT column_list FROM TABLE;

Sanfoundry Global Education & Learning Series – SQL.

To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.