Here is an example of SQL CASE and SQL Union. Here it shows which is better. Click here for SQL Tips and Tricks
SQL Union
Below is the SQL query used by UNION. The example adopted from Craig Mullin’s blog
SELECT CREATOR, NAME, 'TABLE'FROM SYSIBM.SYSTABLESWHERE TYPE = 'T'UNIONSELECT CREATOR, NAME, 'VIEW 'FROM SYSIBM.SYSTABLESWHERE TYPE = 'V'UNIONSELECT CREATOR, NAME, 'ALIAS'FROM SYSIBM.SYSTABLESWHERE TYPE = 'A'ORDER BY NAME;In the above case, the lines of SQL are more, and it takes a lot of time to process it. So, whenever you want to use multiple UNION statements, it is always better to use a CASE statement. Let me share an example of how it can be re-write using CASE.
Related
SQL Case
SELECT CREATOR, NAME,CASE TYPEWHEN 'T' THEN 'TABLE'WHEN 'V' THEN 'VIEW 'WHEN 'A' THEN 'ALIAS'ENDFROM SYSIBM.SYSTABLESORDER BY NAME;Related Posts
