combining results of two select statements

Posted by ErnieStings on Stack Overflow See other posts from Stack Overflow or by ErnieStings
Published on 2010-05-13T12:16:06Z Indexed on 2010/05/13 12:34 UTC
Read the original article Hit count: 163

Filed under:
|
|

I'm using T-SQL with ASP.NET, and c# and i'm pretty new to SQL.

I was wondering how i could combine the results of two queries

Query1:

SELECT tableA.Id,  tableA.Name, [tableB].Username AS Owner, [tableB].ImageUrl, [tableB].CompanyImageUrl, COUNT(tableD.UserId) AS NumberOfUsers
 FROM tableD RIGHT OUTER JOIN 
         [tableB] INNER JOIN
         tableA ON [tableB].Id = tableA.Owner ON tableD.tableAId = tableA.Id
 GROUP BY tableA.Name, [tableB].Username, [tableB].ImageUrl, [tableB].CompanyImageUrl

Query2:

 SELECT tableA.Id,  tableA.Name, COUNT([tableC].Id) AS NumberOfPlans
 FROM   [tableC] RIGHT OUTER JOIN
           tableA ON [tableC].tableAId = tableA.Id
 GROUP BY tableA.Id, tableA.Name

Any help would be much appreciated. Thanks in advance

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql