Multiple Count in One Query. Is this possible? RRS feed

  • Question

  • Hello,

    Is it possible to get the total count of 3 tables in a single query?

    I need to get the Users.Count, Roles.Count and Files.Count.

    Thank You,


    Wednesday, February 22, 2012 11:41 AM


  • Hi MDMoura,

    Welcome to MSDN Forum.

    You can write the T-SQL as below and call it directly in Entity Framework.

    select (select COUNT(*) from Roles ) as roleCount, 
    (select COUNT(*) from Users ) as userCount,
    (select COUNT(*) from Files) as fileCount 

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Allen_MSDN Tuesday, February 28, 2012 1:19 AM
    • Edited by Allen_MSDN Tuesday, March 6, 2012 8:33 AM
    Friday, February 24, 2012 4:38 AM