Get several variables to appear in the sql server?

advertisements

I have two queries:

Select count(*) as countOne where field = '1'
Select count(*) as countTwo where field = '2'

What I want to see after executing these queries in my results viewer:

countOne | countTwo
      23 |      123

How can I get the results from both queries by only running one query?


SELECT COUNT(CASE WHEN field = '1' THEN 1 END) AS countOne,
       COUNT(CASE WHEN field = '2' THEN 1 END) AS countTwo
FROM   YourTable
WHERE  field IN ( '1', '2' )