Link to home
Start Free TrialLog in
Avatar of R8VI
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
ASKER CERTIFIED SOLUTION
Avatar of Jinesh Kamdar
Jinesh Kamdar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of R8VI
R8VI

ASKER

Hi guys thaanks.
I am assuming either should work.
However the first solution by jinesh_kamdar says invalid syntax ')'
I dont know why
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
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
Avatar of R8VI

ASKER

Thank You very much works now much appreciated
Glad to be of help :)