Skip to content
Advertisement

Combine and fuse the results of two SQL queries with UNION

I am writing two seperate SQL queries to get data for two different dates like so:

I tried fusing them like so to get the results for the same number in one row from two different dates:

But it didn’t work as I get the rows for the first query with zeroes for the columns defined as zero followed by the columns of the second query in the same fashion.

How can I correct this to have the desired output ?

Advertisement

Answer

Use conditional aggregation:

If you want the numbers in different rows (which you don’t seem to), then use aggregation:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement