Here is a SQL Server 2005 approach-- prepare sample datadeclare @tbl table (col1 int, col2 int, col3 int, col4 int)insert @tblselect 10, 20, 30, 40 union allselect 20, 10, 40, 30 union allselect 20, 10, 40, 30 union allselect 50, 10, 30, 20-- show the expected outputSELECT DISTINCT p.[1] AS col1, p.[2] AS col2, p.[3] AS col3, p.[4] AS col4FROM ( SELECT d.RowID, -- Not used in outer query but vital for correct result ROW_NUMBER() OVER (PARTITION BY d.RowID ORDER BY d.x) AS ColID, d.x FROM ( SELECT DISTINCT RANK() OVER (ORDER BY t.col1, t.col2, t.col3, t.col4) AS RowID, c.x FROM @tbl AS t CROSS APPLY ( SELECT t.col1 AS x UNION ALL SELECT t.col2 UNION ALL SELECT t.col3 UNION ALL SELECT t.col4 ) AS c ) AS d ) AS yPIVOT ( MIN(y.x) FOR y.ColID IN ([1], [2], [3], [4]) -- MAX, AVG or SUM are equally good for this solution ) AS p
E 12°55'05.25"N 56°04'39.16"EDIT: Colored table prefix for those not familiar with PIVOT operator