create table tb1(id int,username varchar(10))
insert into tb1 select 1,'tom'
insert into tb1 select 2,'bill'
insert into tb1 select 3,'bush'
insert into tb1 select 4,'alice'
insert into tb1 select 5,'bob'
insert into tb1 select 6,'jackson'
insert into tb1 select 7,'juval'
insert into tb1 select 8,'arora'
insert into tb1 select 9,'nitin'
insert into tb1 select 10,'hh'create table tb2(username varchar(10),roleid varchar(10))
insert into tb2 select 'tom',1
insert into tb2 select 'bill',2
insert into tb2 select 'bush',5
drop table tb2select a.id,a.username,isnull(b.roleid,'*') from tb1 a
left join tb2  b
on a.username =b.username

解决方案 »

  1.   

    create table tb1(id int,username varchar(10)) 
    insert into tb1 select 1,'tom' 
    insert into tb1 select 2,'bill' 
    insert into tb1 select 3,'bush' 
    insert into tb1 select 4,'alice' 
    insert into tb1 select 5,'bob' 
    insert into tb1 select 6,'jackson' 
    insert into tb1 select 7,'juval' 
    insert into tb1 select 8,'arora' 
    insert into tb1 select 9,'nitin' 
    insert into tb1 select 10,'hh' create table tb2(username varchar(10),roleid varchar(10)) 
    insert into tb2 select 'tom',1 
    insert into tb2 select 'bill',2 
    insert into tb2 select 'bush',5 
    drop table tb2 select a.id,a.username,isnull(b.roleid,'*') from tb1 a 
    left join tb2  b 
    on a.username =b.username