有三表:table1,table2,table3
table1的字段有:a,b,c,d,e,f
table2的字段有:ID,Name,sex
table3的字段有:ID,Name,country
其中
table1.c=table2.ID
table1.d=table3.ID
现在要将table1的所有字段绑定到datagrid里去
要显示的最终结果为:
a,b,table2.Name,table3.Name,e,f
这个查询语句怎么写?

解决方案 »

  1.   

    select a,b,table2.Name,table3.Name,e,f 
    from table1 inner join 
    table2 on table1.c=table2.ID 
    inner join table 3 on table1.d=table3.ID 
      

  2.   

    select a.a,a.b,b.name,c.name,a.e,a.f from table1 a 
    inner join table2 b on a.c=b.id 
    inner join table3 c on a.d=c.id 
      

  3.   

    select table_1.a,table_1.b,table_2.name,table_3.name,table_1.e,table_1.f
    from table_1,table_2,table_3 where table_2.id = table_1.c and table_3.id=table_1.d
      

  4.   


    select 
             a,b,table2.Name,table3.Name,e,f  
    from 
             table1 
    inner join  
             table2 on table1.c=table2.ID  
    inner join 
             table 3 on table1.d=table3.ID  
      

  5.   

    如果是oracle的话,直接
    select 
             a,b,table2.Name,table3.Name,e,f  
    from 
             table1,table2,table3
    where 
             table1.c=table2.ID(+)
             table1.d=table3.ID(+)
      

  6.   

    方法一:
    select 
             a,b,table2.Name,table3.Name,e,f  
    from 
             table1 
    inner join  
             table2 on table1.c=table2.ID  
    inner join 
             table 3 on table1.d=table3.ID 方法二:
    select table_1.a,table_1.b,table_2.name,table_3.name,table_1.e,table_1.f 
    from table_1,table_2,table_3 where table_2.id = table_1.c and table_3.id=table_1.d推荐方法一,这样可以少访问几次表,增加效率