I am dynamically generating a query like below that creates different combinations of rules by left joining (any number of times) on itself and avoiding rules with some of the same attributes as part of the joins conditions e.g.
SELECT count(*)
FROM rules AS t1
LEFT JOIN rules AS t2
AND ...
LEFT JOIN rules AS t3
AND ...
I am currently removing duplicates by creating an array of ids from the joined rows then sorting and grouping by them:
...
GROUP BY ids
I would like to know if there is a better way of removing duplicate rows e.g.
t1.ID | t2.ID | t3.ID
---------------------
A | B | C
C | B | A
Should be
t1.ID | t2.ID | t3.ID
---------------------
A | B | C
Or
t1.ID | t2.ID | t3.ID
---------------------
C | B | A
But not both.
I would like to go from a permutation of rows to a combination rows.