Sql query question regarding UNION ALL?


#1

Write a SQL query using UNION ALL (not UNION) that uses the WHERE clause to eliminate duplicates?Why might you want to do this?


#2

SELECT supplier_id
FROM suppliers
UNION ALL
SELECT supplier_id
FROM orders
ORDER BY supplier_id;
The SQL UNION ALL operator is used to combine the result sets of 2 or more SELECT statements. It does not remove duplicate rows between the various SELECT statements (all rows are returned). Each SELECT statement within the UNION ALL must have the same number of fields in the result sets with similar data types.