How to rewrite this query so as not to use union clause

How to rewrite this query DO NOT use the UNION clause (UNION ALL):

SELECT c FROM a UNION SELECT c FROM b 

expected result (the recordset must match):

 SELECT c FROM .... 
+4
source share
1 answer

To get the same results as your query above, you can do this:

 SELECT COALESCE(ac, bc) AS c FROM a FULL OUTER JOIN b ON bc = ac 

However, this will give you the same results as UNION, which is not quite the same as UNION ALL (since duplicates will be deleted). To execute UNION all, you will need to do the same, but the join condition will not be fulfilled:

 SELECT COALESCE(ac, bc) AS c FROM a FULL OUTER JOIN b ON 1 = 0 

In any case, I'm not sure if it will be much faster than using UNION.

+7
source

All Articles