selectu.username,max(case when testid = 1 then datetaken else null end) as A,max(case when testid = 2 then datetaken else null end) as B,max(case when testid = 3 then datetaken else null end) as C,max(case when testid = 4 then datetaken else null end) as D,max(case when testid = 5 then datetaken else null end) as Efrom users as uleft join passes as p on u.userid = p.useridgroup by u.userid



