一表t1:
商品编码  商品名  数量
------------------------
c         牙膏    1
b         毛巾    2
a         杯子    1一表t2:
序号   商品编码
---------------
1      a
2      b
3      c我想按照表t2的序号升序排序后,按照得到下结果:
商品编码  商品名  数量
------------------------
a         杯子    1
b         毛巾    2
c         牙膏    1求语句:

解决方案 »

  1.   

    select t1.* from t1 ,t2
    where t1.商品编码=t2.商品编码
    order by t2.序号
      

  2.   

    我用left join 连接2表会出现重复行记录,但我又不想用distinct,请教语句
      

  3.   

    --> 测试数据:@tb
    declare @tb table([商品编码] varchar(1),[商品名] varchar(4),[数量] int)
    insert @tb
    select 'c','牙膏',1 union all
    select 'b','毛巾',2 union all
    select 'a','杯子',1select * from @tb order by 商品编码