250+ TOP MCQs on Performing Multiple – Table Retrievals with Union and Answers

MySQL Database Multiple Choice Questions 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

Answer: d
Clarification: 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

Answer: b
Clarification: 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.

3. The following SQL statement is invalid.

SELECT abc, xyz FROM table1 UNION abc, def FROM table2;

a) True
b) False

Answer: b
Clarification: 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.

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

Answer: d
Clarification: 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

Answer: a
Clarification: 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.

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

Answer: b
Clarification: 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

Answer: b
Clarification: 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

Answer: a
Clarification: 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

Answer: b
Clarification: 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

Answer: a
Clarification: 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’.

Leave a Reply

Your email address will not be published. Required fields are marked *