0

I have two tables from which I need to extract the NUMBER of rows belonging to the same ID.

Orders Table
Positions Table

I'm trying to build a query that will get me the amount of matching rows from the two tables, based on a common ID. I'm not looking for a result set that will return all matching rows, I only need back one value with the amount of matching rows found.

I've tried this next query, but I know there are in fact 48 rows when it returns 50.

 select Isnull(CntPos,0)+IsNull(CntOrd,0)
 from  (select CID
             ,Count(*) CntPos  
        from  [Serv].[Trade].[Position] 
        Group By CID
       ) Pos
 Full join (select CID
                ,Count(*) CntOrd  
            from  [Serv].[Stocks].[Orders] 
            Group By CID
           ) Ord 
     on Ord.[CID] = Pos.CID
 WHERE Ord.CID=19556
Daniel E.
  • 2,029
  • 3
  • 22
  • 28
Yosi199
  • 1,745
  • 4
  • 22
  • 47
  • 2
    Possible similar [question](http://stackoverflow.com/questions/1279569/sql-combine-select-count-from-multiple-tables). – Nathan Mar 30 '14 at 07:01
  • Duplicate of this > http://stackoverflow.com/questions/1279569/sql-combine-select-count-from-multiple-tables – Yosi199 May 08 '14 at 05:10

0 Answers0