Firstly welcome to Stackoverflow.
Assuming you are on at least SQL Server 2008, you can achieve this using row_number() and a self-join
To show how this works, I give a simple example:
declare @test table(username varchar(50), email varchar(50))
insert INTO @test values('username1', 'email1@test.com')
insert INTO @test values('username1', 'email2@test.com')
insert INTO @test values('username2', 'email3@test.com')
;with cte as
(SELECT username, email, row_number() OVER (PARTITION BY username order by username) rn
from @test)
SELECT t1.username, t1.email as email1, t2.email as email2
FROM cte t1
LEFT JOIN cte t2 ON t1.username = t2.username AND t2.rn = 2
WHERE t1.rn = 1
By way of explanation, row_number() gives a unique number for each line, determined by the ORDER BY within the OVER. Adding PARTITION BY resets the row count for each new value specified by the PARTITION. In this case PARTITION BY and ORDER BY are the same field, but they need not be. Putting this all in a common table expression, then allows you to do a self-join (in this case an outer self-join) to pick up both those users with two emails (where rn will be 1 and 2) and those with just one. The left side of the join contains those with rn 1 (which will be all users), whilst the right side picks up the 2s.
Hope this helps
Jonathan