select max(case rownumber %3when2then id elsenullend) as id1, max(case rownumber %3when2then[text]elsenullend) as text1, max(case rownumber %3when1then id elsenullend) as id2, max(case rownumber %3when1then[text]elsenullend) as text2, max(case rownumber %3when0then id elsenullend) as id3, max(case rownumber %3when0then[text]elsenullend) as text3 from (select row_number() over(orderby[type]desc) as rownumber,[id],[text]from tablename) A groupby (rownumber+2)/3