Adding multiple select count results in MYSQL

2

I am trying to add all the clients I have in all my databases, so for this I am doing the following query :

SET @total = 0;

USE BASE x1; SELECT @total:= @total +COUNT(1) FROM clientes;

USE BASE x2; SELECT @total:= @total +COUNT(1) FROM clientes;

In the current scenario my variable is taking its value and adding it to the value of COUNT(1) ;

But every query is performed, a result is displayed, I wish it were only the final result!

    
asked by anonymous 29.05.2015 / 20:08

1 answer

4

You can sum the result of a SubSelect

SELECT 
     SUM(CLIENTES) 
FROM (
        SELECT 
            COUNT(1) AS CLIENTES FROM X1.CLIENTES
    UNION ALL
        SELECT 
            COUNT(1) AS CLIENTES FROM X2.CLIENTES
     )  AS T
    
29.05.2015 / 20:44