SELECT p1.name product1,p2.name product2,COUNT(DISTINCT t.id) joint_sales FROM products p1 JOIN transaction_sell_lines tsl1 ON p1.id=tsl1.product_id JOIN transactions t ON tsl1.transaction_id=t.id JOIN transaction_sell_lines tsl2 ON t.id=tsl2.transaction_id JOIN products p2 ON tsl2.product_id=p2.id WHERE t.type="sell" AND p1.id<p2.id GROUP BY p1.id,p2.id,p1.name,p2.name ORDER BY joint_sales DESC;