multiple counts each using a join of 2 tables union all another count that also joins two tables

Todd Brower 20 Reputation points
2023-01-24T15:17:02.1433333+00:00

have 4 tables..1,2,3,4..need to

join tables 1 & 2

union all

join tables 3 & 4

return just one count from the union

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Tom Cooper 8,481 Reputation points
    2023-01-24T16:08:35.6+00:00

    Providing sample tables and data and the result you would want from that sample data would make your question more clear, but something like

    ;With cte
     As
    (Select <column list>
    From Table1
    Inner Join Table2 On <join condition>
    Union All
    Select <column list>
    From Table3
    Inner Join Table4 On <join condition>)
    Select Count(*) From cte;
    
    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.