MySQL Questions and Answers – Performing Multiple – Table Retrievals with Union

This set of MySQL Database Multiple Choice Questions & Answers (MCQs) focuses on “Table Retrievals with Union”.

1. To combine multiple retrievals, we write several SELECT statements and put the keyword between them. What is the keyword?
a) COMBINE
b) CONCAT
c) JOIN
d) UNION
View Answer

Answer: d
Explanation: The ‘UNION’ operator is used for combining the results of various ‘SELECT’ queries into one. For example, ‘SELECT a FROM table1 UNION SELECT a FROM table2;’ produces the results from tables table1 concatenated with that of table2.

2. What is ‘xyz’ in the following SQL statement?

SELECT xyz FROM table1 UNION xyz FROM table2;

a) row name
b) column name
c) table name
d) database name
View Answer

Answer: b
Explanation: The ‘SELECT’ queries can be combined together using the ‘UNION’ operator to produce the concatenated results from two or more tables. The data type of the columns is not taken into account.
advertisement
advertisement

3. The following SQL statement is invalid.

Note: Join free Sanfoundry classes at Telegram or Youtube
SELECT abc, xyz FROM table1 UNION abc, def FROM table2;

a) True
b) False
View Answer

Answer: b
Explanation: Even if the columns ‘xyz’ and ‘def’ have different data types, the results from these columns are placed into the column ‘xyz’. The data types can be determined from the values in the columns.
advertisement

4. Which keyword used with UNION does not retain duplicate rows?
a) ALL
b) NARROW
c) STRICT
d) DISTINCT
View Answer

Answer: d
Explanation: The keyword ‘DISTINCT’ used along with ‘UNION’ is synonymous with just the ‘UNION’ statement. It produces only the distinct rows from the combination of the two tables in the SELECT query.

5. Which keyword used with UNION retains duplicate rows?
a) ALL
b) NARROW
c) STRICT
d) DISTINCT
View Answer

Answer: a
Explanation: The keyword ‘ALL’ used along with ‘UNION’ is not synonymous with just the ‘UNION’ statement. It produces the duplicate rows, if they exist, from the combination of the two tables in the SELECT query.
advertisement

6. The UNION ALL has a higher precedence than UNION DISTINCT.
a) True
b) False
View Answer

Answer: b
Explanation: When there is a mixture of ‘UNION’ or ‘UNION DISTINCT’ statements with the ‘UNION ALL’ statements, any distinct union operation takes precedence over any ‘UNION ALL’ operations to its left.

7. Which clause is used to sort a UNION result as a whole?
a) LIMIT
b) ORDER BY
c) GROUP BY
d) SORT
View Answer

Answer: b
Explanation: The ‘ORDER BY’ clause is used along with the ‘UNION’ statement to sort a ‘UNION’ result as a whole. It is placed after the last ‘SELECT’ statement which is kept in parentheses.

8. Suppose it is desired that UNION operation should return not more than 3 rows. Which keyword is used for this?
a) LIMIT
b) RESTRICT
c) COUNT
d) SORT
View Answer

Answer: a
Explanation: When there is a need to put a limit to the number of rows returned by the ‘UNION’ operation, the statement ‘LIMIT’ is appended to the ‘SELECT’ queries which are joined by the ‘UNION’ operations.

9. Which table is used to run a UNION-type query on MyISAM tables?
a) TRADITIONAL
b) MERGE
c) SERVELET
d) UNITE
View Answer

Answer: b
Explanation: When there is a need to run a ‘UNION type’ operation on a MyISAM table that has the same structures, a ‘MERGE’ table is set up for it. After this, the queries are performed on this table.

10. SELECT on a MERGE table is like _____________
a) UNION ALL
b) UNION
c) UNION DISTINCT
d) JOIN
View Answer

Answer: a
Explanation: Performing a ‘SELECT’ operation on a ‘MERGE’ table is like performing ‘UNION ALL’. This means that duplicate row results are not removed. ‘SELECT DISTINCT’ is like ‘UNION’ or ‘UNION DISTINCT’.

Sanfoundry Global Education & Learning Series – MySQL Database.

To practice all areas of MySQL Database, 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.