R8VI
asked on
SQL Union Count SUM quey
I have the following query it return two rows with values of 300 and 12 what i need to do is get the total of both Rows and display one answer.
Any help is much appreciated.
SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL
Any help is much appreciated.
SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
jinesh_kamdar's solution is more efficient, just add 'as A'
SELECT SUM(total) FROM
(SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL) as A
SELECT SUM(total) FROM
(SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL) as A
I always mess up with the aliases. faiga16 is right. Just add the alias and you should be good.
SELECT SUM(A.total) FROM
(SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL) as A
SELECT SUM(A.total) FROM
(SELECT Count (SId) As Total From R Where SID='HL'
UNION
SELECT Count(1) As Total FROM Archive where Closed IS NULL) as A
ASKER
Thank You very much works now much appreciated
Glad to be of help :)
ASKER
I am assuming either should work.
However the first solution by jinesh_kamdar says invalid syntax ')'
I dont know why