Commalists, as you found, are a clumsy way to store lists. Instead, use a many-to-many mapping table: CREATE TABLE toppings ( pizza_id SMALLINT UNSIGNED NOT NULL, topping SMALLINT UNSIGNED NOT NULL, PRIMARY KEY(pizza_id, topping), INDEX(topping, pizza_id) ENGINE=InnoDB; Then your task becomes simply SELECT a.pizza_id, a.topping FROM toppings AS a JOIN toppings AS b ON b.topping = a.topping AND b.pizza_id > a.pizza_id To get the commalist (like you started with) SELECT pizza_id, GROUP_CONCAT(topping) FROM toppings GROUP BY pizza_id;