Yes, you need to do a self join on the table, here's an example:declare @temp table(TransactionID int, ProductID int)insert @tempselect 0, 1 union allselect 0, 2 union allselect 0, 5 union allselect 1, 2 union allselect 1, 5 union allselect 1, 6 union allselect 2, 6 union allselect 3, 1 union allselect 3, 5select t1.ProductID, t2.ProductID, count(*) from @temp t1inner join @temp t2 on t1.TransactionID = t2.TransactionID and t1.ProductID < t2.ProductIDgroup by t1.ProductID, t2.ProductIDorder by 3 desc