Compute sum of counts using union
SELECT COUNT(id) AS Cuenta FROM prerating_calculos 
WHERE usuario NOT LIKE 'TEST' AND usuario NOT LIKE 'ADMIN' 
UNION SELECT COUNT(id) AS Cuenta FROM prerating_calculos_apx 
WHERE usuario NOT LIKE 'TEST' AND usuario NOT LIKE 'ADMIN' 

This is what it shows me

----------   
| Cuenta |
----------
|   1    |
----------
|   75   |
----------

This is what I want you to show me

----------   
| Cuenta |
----------
|   76   |
----------

Answer #1:

What you need to do is to implement a subselect, selecting the sum from your initial query.

SELECT SUM(Cuenta) FROM
    (SELECT COUNT(id) AS Cuenta FROM prerating_calculos 
    WHERE usuario NOT LIKE 'TEST' AND usuario NOT LIKE 'ADMIN' 
    UNION SELECT COUNT(id) AS Cuenta FROM prerating_calculos_apx 
    WHERE usuario NOT LIKE 'TEST' AND usuario NOT LIKE 'ADMIN') AS T1
Answered By: PaulS
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .



# More Articles