现在有2张表:
表a如下
字段1   字段2    字段3
公司id   公司名 
表b如下(公司id对于表a字段1)
字段1      字段2      字段3
公司id    公司id  字段值3怎么写出语句达到如下效果:按表a、b中公司id一一对应的原则 查出公司名,也就是替换表b中的公司id为表a中的公司名并按表b字段3的条件查询
谢咯~~~~~~~~~~~

解决方案 »

  1.   

    select b.字段1,a.字段2,b.字段3 from 表a a,表b b
    where a.字段1=b.字段1
    and b.字段3='xxxx'
      

  2.   

    其实就是表b中的字段2的公司id用a表中的名称代替
      

  3.   

    update b set 字段1=a.字段2 from a,b where b.字段1=a.字段1 and b.字段3='xxxx'
      

  4.   

    update b set 字段1=a.字段2 from a,b where b.字段1=a.字段1 
      

  5.   

    不好意思 估计我说的太罗嗦了就是表b中包含有表a中的公司id都查出对应的公司名就行了 
      

  6.   

    select a.字段2 b1,c.字段2 b2,b.字段3
    from b left join a on b.字段1 = a.字段1
           left join a c on b.字段2 = c.字段1
    where b.字段3 ...
      

  7.   

    表1 left join 表2 
      

  8.   


    如果B表字段2对应A表字段1的话
    select 字段2 from a where exists(select 1 from b where 字段2=a.字段2)[/code]