dos consultas de selección con diferente cláusula where en la misma tabla

Tengo un seguidor de table y la count siguiente …

desea get el recuento de ambos en un procedimiento almacenado … ¿es posible tener dos consultas de selección con diferentes condiciones en la misma condición posible?

CREATE TABLE Table1 ([val1] int, [val2] int, [val3] int, [val4] int, other int) ; INSERT INTO Table1 ([val1], [val2], [val3], [val4], other) VALUES (1, 26, 13, 1, 1), (2, 13, 26, 1, 1), (3, 10, 26, 1, 1), (4, 26, 13, 1, 1), (5, 14, 26, 1, 1) ; 

MY selects de consultas

 (select count(*) as following_count from table1 where val2=26) (select count(*) as follower_count from table1 where val3=26) 

SQL FIDDLE LINK

Podrías hacer esto:

 SELECT SUM(CASE WHEN val2=26 THEN 1 ELSE 0 END) AS following_count, SUM(CASE WHEN val3=26 THEN 1 ELSE 0 END) AS follower_count FROM table1 

¿Por qué no disparas ambas declaraciones usando UNION ALL?

Ver: http://dev.mysql.com/doc/refman/5.1/de/union.html

ASI QUE:

 SELECT COUNT(*) AS following_count FROM table1 WHERE val2=26 UNION ALL SELECT COUNT(*) AS following_count FROM table1 WHERE val3=26 

devuelve dos filas con 2 numbers en 1 consulta.

En dos columnas haz esto:

 SELECT (SELECT COUNT(*) AS following_count FROM table1 WHERE val2=26) col1 , (SELECT COUNT(*) AS following_count FROM table1 WHERE val3=26) col2 

Solo agrega punto y coma a tus declaraciones …

 (select count(*) as following_count from table1 where val2=26); (select count(*) as follower_count from table1 where val3=26);