, , (, 100 ),
select
u.username,
isnull(ut1.Usertypeid,0) as Type1,
isnull(ut2.Usertypeid,0) as Type2,
isnull(ut3.Usertypeid,0) as Type3,
isnull(ut4.Usertypeid,0) as Type4,
isnull(ut5.Usertypeid,0) as Type5,
isnull(ut6.Usertypeid,0) as Type6
from
users u
left outer join
userstype ut1 on u.userid = ut1.userid and ut1.usertypeid = 1
left outer join
userstype ut2 on u.userid = ut2.userid and ut2.usertypeid = 2
left outer join
userstype ut3 on u.userid = ut3.userid and ut3.usertypeid = 3
left outer join
userstype ut4 on u.userid = ut4.userid and ut4.usertypeid = 4
left outer join
userstype ut5 on u.userid = ut5.userid and ut5.usertypeid = 5
left outer join
userstype ut6 on u.userid = ut6.userid and ut6.usertypeid = 6
10- , , (, 10-), , !
,
select
u.username,
ut..Usertypeid
from
users u
left outer join
userstype ut
on u.userid = ut.userid
,
Username | UserTypeID
---------------------
Joe | 3
Joe | 4
, !