The UNION
operator is used to combine the result-set of two or more queries.
The queries in the union must follow these rules:
Combine products
and testproducts
using the UNION
operator:
SELECT product_id, product_name
FROM products
UNION
SELECT testproduct_id, product_name
FROM testproducts
ORDER BY product_id;
Run Example »
With the UNION
operator, if some rows in the two queries returns the exact same result, only one row will be listed, because UNION
selects only distinct values.
Use UNION ALL
to return duplicate values.
Let's make some changes to the queries, so that we have duplicate values in the result:
SELECT product_id
FROM products
UNION
SELECT testproduct_id
FROM testproducts
ORDER BY product_id;
Run Example »
SELECT product_id
FROM products
UNION ALL
SELECT testproduct_id
FROM testproducts
ORDER BY product_id;
Run Example »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!