Here is the basics. There might be other things you need to do (LEFT OUTER JOIN) depending on your actual data (i.e.: if a Stock item hans't been sold):DECLARE @table1 TABLE (items varchar(50), stock int)INSERT @table1 VALUES('banana', 40),('apple', 40),('melon', 40)DECLARE @table2 TABLE (items varchar(50), quantity int)INSERT @table2 VALUES('banana', 5),('banana', 7),('apple', 3),('melon', 2),('apple', 5)SELECT a.items, (a.stock - b.quantity) AS stockFROM @table1 AS aINNER JOIN ( SELECT items, SUM(quantity) AS quantity FROM @table2 GROUP BY items ) AS b ON a.items = b.items