Does this require a UNION?
SELECT vend_id, prod_id, prod_price
FROM products
WHERE prod_price <= 5
UNION
SELECT vend_id, prod_id, prod_price
FROM products
WHERE vend_id IN (1001,1002);
Or is it the same if you do it this way?
SELECT vend_id, prod_id, prod_price
FROM products
WHERE prod_price <= 5
OR vend_id IN (1001,1002);
The database would generate a different execution plan for both queries. Without an actual performance problem, I’d go with the simpler query. Replacing
orwithunionmakes a simple query moderately complex. But it would make a complex query impossibly hard to understand.There are also slight differences between both queries. The database will filter out duplicates for the second query (you’re using
union, notunion all.) This can have surprising effects if you filter on columns you’re not selecting.