Count from inner select statement

18,145

I suppose you just missed the name of the second column:

SELECT COUNT(*)
FROM (
    Select id, COUNT(id) count_of_id
    FROM [Testing].[dbo].[Bench]
    GROUP BY id
    HAVING COUNT(*) =5
);
Share:
18,145
Huzaifa
Author by

Huzaifa

Updated on July 24, 2022

Comments

  • Huzaifa
    Huzaifa almost 2 years

    I am trying to execute the following query in SQL server but I am getting error. Can somebody explain me how to count the inner select statement?

    SELECT COUNT(*) from
    
    (Select ID,
          COUNT(ID)
      FROM [Testing].[dbo].[Bench] group by ID  having COUNT(*) =5);
    
  • Huzaifa
    Huzaifa about 11 years
    AAaaahhhh! Silly me. You are right. Thank you very much.
  • Taryn
    Taryn about 11 years
    SQL Server requires an alias on the subquery.