select * from news left join newslb on news.sortid=newslb.id2

解决方案 »

  1.   

    declare @news table(id1 int, title  varchar(20),sortid int)
    declare @newslb table(id2 int,lbtitle varchar(20))
    insert @news
    select 1,'title1',1 union
    select 2,'title2',2 union
    select 3,'title3',1insert @newslb 
    select 1,'sort1' union select 2,'sort2'select * from @news news left join @newslb newslb on news.sortid=newslb.id2--结果
    /*
    id1         title                sortid      id2         lbtitle  
    ----------- -------------------- ----------- ----------- ---------
    1           title1               1           1           sort1
    2           title2               2           2           sort2
    3           title3               1           1           sort1(所影响的行数为 3 行)
    */
      

  2.   

    select a.*,b.lbtitle from news a,newslb b where a.sortid = b.id2orselect a.*,b.lbtitle from news a inner join newslb b on a.sortid = b.id2