现有两个表codeTable 表
code  codename
1      是
0      否
infoTable 表
字段1  字段2 字段3  code
现在想从infoTable 表中查出信息,并将code相对应的 codename也想显示出来,那该sql语句该如何写?

解决方案 »

  1.   

    SELECT A.字段1,A.字段2,A.字段3,B.CODENAME FROM infoTable A
    LEFT JOIN codeTable B ON A.CODE=B.CODE
      

  2.   


    select * from codetable x,infotable y where x.code=y.code;
      

  3.   

    select a.字段1,a字段2,a.字段3,b.codename from infoTable a 
    left join codeTable b on a.code=b.com
      

  4.   

    select t.字段1, t.字段2, t.字段3, t1.codename
      from infoTable t, codeTable t1
     where t.code = t1.code(+)
      

  5.   

    select * from codetable x,infotable y where x.code=y.code;
      

  6.   


    再补充一点吧:
    code  codename codetype
    1      是          a
    0      否          a
    1      好          b
    0      坏          b
    infoTable 表 
    字段1  字段2 字段3  a   b
    值1    值2    值3  0   1
    值6     值4   值5  1   0

    这时想得到infoTable 中的所有信息,并且得到a,b相应类型所得的codename值,应该如何写sql?