none
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,

    Miguel

    Wednesday, February 22, 2012 11:41 AM

Answers

  • 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


    Friday, February 24, 2012 4:38 AM
    Moderator