Select Count(*) From ( Select ... From TempTable Group By column_1, column_2, column_3, column_4 ) As Z