Tag Archive for 'Union'

SQL Union All

I was working in this certain module last week wherein I will create a web app page that will generate monthly reports. Everything was fine and I manage to do it with an ease until the boss checks my work, On the report generated, there was a certain field column wherein NULL values are present, though some has a value, still it is impossible because that field is required in the form, and so the 1st problem occurs

In that module, what I did is I created a views in sql wherein it contains the computations of the data selected from a certain table, and I also added a field named “officerFld” which will contain an officer’s name selected from a certain field from another table.

I started to investigate the problem and found out that the officer’s name is stored in two different tables wherein I only selected from one of those tables. So I started searching for a way on how to select those officer’s name from the second table and insert it on the “officerFld” on the views that i’ve created, in that case, all the NULL values will be replaced by the officer’s name from the second table and all the officer’s name from the first table will still remain in the “officerFld” found on the views that i created.

Thanks to kiko(my older brother), who gave me the idea to use the UNION ALL command in sql. Well, I’m just starting to learn sql so don’t expect me to know all the commands. But now I’m starting to acquire knowledge so that’s what i did, i used the UNION ALL command in sql to combine the results of my two queries together and I used LEFT OUTER JOIN to combine it to my views.