I have two queries that I\'m UNION
ing together such that I already know there will be no duplicate elements between the two queries. Therefore, UNION
a
I would use UNION ALL
anyway. Even though you know that there are not going to be duplicates, depending on your database server engine, it might not know that.
So, just to provide extra information to DB server, in order for its query planner a better choice (probably), use UNION ALL
.
Having said that, if your DB server's query planner is smart enough to infer that information from the UNION
clause and table indexes, then results (performance and semantic wise) should be the same.
Either case, it strongly depends on the DB server you are using.