MDAC 2.5 SDK - OLE DB Programmer's Reference
Chapter 26: Mapping MDX to SQL Statements
This section explains how the UNION function handles duplicates.
Consider UNION(S1, S2) where:
S1 = {Kansas, Buffalo, Topeka, USA, Canada}
S2 = {Kansas, Topeka, Wichita, Canada}
As shown in the section "Literal Sets," create two tables—S1 and S2—that contain the fully qualified member names in the sets S1 and S2, respectively.
The following query does the union:
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 does the following:
Consider UNION(S1, S2, [ALL]). As in the preceding section, create the tables S1 and S2. Then 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 with a list of columns (which is equivalent to the number of dimensions in the input sets).