Sample Header Ad - 728x90

Using same table in a UNION multiple times

1 vote
1 answer
4900 views
I am given a query that is using the same table with same columns and filters multiple times and the only thing is changing is the Type which is given manually. I am thinking there must be a better way to do that. Query statement is like below: Select Column 1, Column 2, Sum(Column 3) AS Test, "First Query" AS "Type" From Table X Where Column 1 = "Fly" Group by Column 1, Column 2 UNION ALL Select Column 1, Column 2, Sum(Column 3) AS Test, "Second Query" AS "Type" From Table X Where Column 1 = "Fly" Group by Column 1, Column 2 UNION ALL Select Column 1, Column 2, Sum(Column 3) AS Test, "Third Query" AS "Type" From Table X Where Column 1 = "Fly" Group by Column 1, Column 2 Thanks!
Asked by Nil R (113 rep)
Apr 21, 2021, 04:11 AM
Last activity: Apr 21, 2021, 05:17 AM