Return rows with a column that tells how many times id is in another table
Posted on 2009-06-27
I have 2 tables. I want to return everything from Table1 where ItemId=2. I want to add one column CountUnits that tells how many times UnitId exists in Table2. How do I write a stored procedure for this?
T1Id, ItemId, UnitId, T1Name
T2Id, UnitId, T2Name.
Return: T1Id, ItemId, UnitId,T1Name, CountUnits