SQLite - Remove duplicates across multiple columns
WITH RECURSIVE cte AS 
( SELECT c1, c2, c3, 1 level
  FROM test
UNION ALL
  SELECT cte.c1, t2.c2, GREATEST(cte.c3, t2.c3), level+1
  FROM cte
  JOIN test t1 ON cte.c2 = t1.c2
  JOIN test t2 ON t1.c1 = t2.c1
  WHERE t2.c3 != cte.c3
    AND level &lt; ( SELECT MAX(c3)
                  FROM test )
UNION ALL
  SELECT t2.c1, cte.c2, GREATEST(cte.c3, t2.c3), level+1
  FROM cte
  JOIN test t1 ON cte.c1 = t1.c1
  JOIN test t2 ON t1.c2 = t2.c2
  WHERE t2.c3 != cte.c3
    AND level &lt; ( SELECT MAX(c3)
                  FROM test )
)
SELECT cte.c1, cte.c2, MAX(cte.c3) c3
FROM cte
JOIN test ON (cte.c1, cte.c2) = (test.c1, test.c2)
GROUP BY c1, c2
HAVING c3 = MAX(test.c3);


fiddle