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.
  • 1,999
  • 3
  • 20
  • 28
Yosi199
  • 1,685
  • 4
  • 21
  • 45

0 Answers0