Consider UNION(S1, S2) where:
S1 = {Kansas, Buffalo, Topeka, USA, Canada}
S2 = {Kansas, Topeka, Wichita, Canada}
SELECT Name, Newrank AS Rank
FROM
(((SELECT Name, "1" AS Src, Rank FROM S1
UNION ALL
SELECT Name, "2" AS Src, Rank FROM S2)
RANKTOP 1 ROWS RANKORDER BY Src, Rank RANKGROUP BY Name)
RANK ROWS AS NewRank RANKORDER BY Src, Rank)
ORDER BY Rank
In English, the query:
Consider UNION(S1, S2, ALL). As in the previous section, tables are generated for S1 and S2. Then you use the following query:
SELECT Name, Newrank AS Rank
FROM
((SELECT Name, "1" AS Src, Rank FROM S1
UNION ALL
SELECT Name, "2" AS Src, Rank FROM S2)
RANK ROWS AS NewRank RANKORDER BY Src, Rank)
ORDER BY Rank
This is simpler because you need not remove duplicates. After the union, the Rank operation generates a rank value for each of the rows of the table joined by union. The outer SELECT emits this table, ordering it by the NewRank (renamed as Rank) column.
Each tuple has more than one element for these sets. Replace the Name column in the select list of each SELECT statement above by a list of columns (which is equivalent to the number of dimensions in the input sets).