The GROUP BY clause in SQL is used to get only unique rows. You have to specify only the columns you want them evaluated by – and the same ones both after GROUP BY and after SELECT. The only exception is aggregate functions (SUM,AVG, etc.). That is not a problem at all, though, because (with a correct query) it returns only unique rows, so you can then easily get a primary key value or any other important values.
It is still faster than fetching more rows and then doing this in the server-side code, where there is also a risk that you make a mistake and, in the worst case, lose data. So, for example, we have this table:
And this SQL statement:
use SqlServerLearn;
SELECT c1,c2,MAX(c4) FROM test4 GROUP BY c1,c2
GOIt returns this output:

As you can see, we got back only the rows with unique combinations of the columns c1, c2, and note that it was not the first row that came back, but the second one, because we applied the MAX function to c4. Let me also show you what SQL Server would print if you tried to select a column that is not listed in GROUP BY:
use SqlServerLearn;
SELECT c1,c2,c3,MAX(c4) FROM test4 GROUP BY c1,c2
GO