Q1
True / FalseIn MySQL, the UNION operator combines the results of two or more SELECT statements and removes duplicate rows.
The UNION operator in MySQL combines results from multiple SELECT statements and automatically removes duplicate rows.
Q2
True / FalseUNION ALL in MySQL includes duplicates in the result set.
The UNION ALL operator includes all rows from each SELECT statement, including duplicates.
Q3
True / FalseThe number of columns in each SELECT statement used with UNION must be different.
The number of columns in each SELECT statement must be the same when using UNION or UNION ALL, though the column names can be different.
Q4
True / FalseThe ORDER BY clause can be used with UNION or UNION ALL to sort the final result set.
You can use the ORDER BY clause with UNION or UNION ALL, but it must be placed at the end of the entire query.
Q5
True / FalseMySQL requires that all SELECT statements in a UNION query have the same column names.
MySQL does not require the same column names, but the number and data types of columns must match.
Q6
True / FalseUsing UNION ALL is generally faster than using UNION because UNION ALL does not perform a duplicate check.
UNION ALL can be faster than UNION because it does not need to check for and remove duplicate rows.
Q7
True / FalseYou can use UNION or UNION ALL with subqueries in MySQL.
MySQL allows UNION or UNION ALL to combine results from subqueries, provided each subquery has the same number of columns with compatible data types.
Q8
True / FalseThe UNION operator can only be used with SELECT statements that have columns of exactly the same data types in MySQL.
For UNION to work, the corresponding columns in each SELECT statement must have compatible data types.
Q9
True / FalseYou can use LIMIT in conjunction with UNION ALL to limit the number of rows returned in MySQL.
You can use LIMIT with UNION ALL to limit the rows returned from the entire combined result set.
Q10
True / FalseWhen using UNION in MySQL, the columns selected must be in the same order for each SELECT statement involved.
In MySQL, when using UNION, the columns must be in the same order in each SELECT statement for the combined results to be meaningful.
Q17
Single ChoiceWhich of the following queries will return all rows from both the sales and purchases tables, including duplicates, while sorting the result set by transaction_date in descending order?
UNION ALL is used to keep duplicates, and ORDER BY is used to sort the results by transaction_date in descending order.
Q19
Single ChoiceConsider two tables orders_2023 and orders_2024, each having columns order_id and order_date. Write a query using UNION ALL that lists all orders from both tables without removing duplicates and sorts the results by order_date in ascending order. Which query would you use?
UNION ALL ensures all records are included, and ORDER BY sorts the combined result set by order_date.
Q20
Single ChoiceGiven two complex queries that retrieve data from several joined tables, you want to combine their results, remove duplicates, and then sort by a calculated column (e.g., total_sales). How would you structure your query in MySQL?
Subqueries: Each subquery calculates total_sales for each customer_id from different tables (e.g., sales_2023 and sales_2024). UNION: Combines the results of the subqueries and removes any duplicate rows. ORDER BY: Sorts the final combined result by total_sales in descending order (DESC).
Q21
Multiple ChoiceWhich SQL query uses UNION to combine the results from the 'employees' and 'managers' tables, returning unique records?
SQL Code
SELECT employee_id, name FROM employees
UNION
SELECT manager_id, name FROM managers;
The UNION operator is used to combine the results from two SELECT statements, returning unique records by default.
Q22
Multiple ChoiceIdentify the correct SQL query that uses UNION ALL to combine the results from the 'orders' and 'shipments' tables, including all duplicate records.
SQL Code
SELECT order_id, order_date FROM orders
UNION ALL
SELECT shipment_id, shipment_date FROM shipments;
The UNION ALL operator combines the results from two SELECT statements, including all duplicate records.
Q25
Multiple ChoiceWhich SQL query uses UNION to combine the results from the 'current_employees' and 'former_employees' tables, ensuring no duplicates are returned?
SQL Code
SELECT employee_id, name FROM current_employees
UNION
SELECT employee_id, name FROM former_employees;
The UNION operator combines the results from the two SELECT statements, removing duplicates from the final result set.
Q28
Multiple ChoiceWhich SQL query uses UNION ALL to combine the results from the 'north_america_sales' and 'europe_sales' tables, showing all sales records including duplicates?
SQL Code
SELECT sale_id, amount FROM north_america_sales
UNION ALL
SELECT sale_id, amount FROM europe_sales;
The UNION ALL operator is used to include all sales records from both tables, including duplicates.
Q30
Multiple ChoiceWhich SQL query uses UNION ALL to combine the results from the 'domestic_sales' and 'international_sales' tables, showing all sales records including duplicates?
SQL Code
SELECT sale_id, total_amount FROM domestic_sales
UNION ALL
SELECT sale_id, total_amount FROM international_sales;
The UNION ALL operator is used to include all sales records from both tables, including duplicates.