I have a sparsely populated matrix that's the result of a series of left joins. I'd like to collapse it down to a single row (see below). The only solution I've seen to this is a GROUP BY on the PK and a MAX() on ColA, ColB etc. Performance is a huge issue here, so I'd like to know if anyone has a better solution. The columns ColA, ColB etc are rows that have been pivoted to columns. My understanding is that I can't use a PIVOT because the columns are coming from rows (1 to n) and could change at any given time. I have a sparsely populated matrix that's the r