表1,languageId   IsDefault  Code   IsUse
1       true     cn      true
2       false    en      true
3       false    jp      true表2,Catalog
Id    CatalogName   language   CatalogGuid
1      类别1          cn        3A41058F
2      类别1          en        3A41058F
3      类别1          jp        3A41058F
4      类别2          cn        8A5C7D4B
5      类别2          en        8A5C7D4B
6      类别2          jp        8A5C7D4B表,products
Id   name    language    CatalogGuid
1    产品1   cn           3A41058F
2    产品1   en           3A41058F
3    产品1   jp           3A41058F
4    产品2   cn           3A41058F
5    产品2   en           3A41058F
6    产品2   jp           3A41058F你只是想读出默认语言版本下的所有产品,然后关链一下类别表读出类别,结果搞了半天都不行,糊涂了都
能不能帮我看一下应该怎么写sql语句

解决方案 »

  1.   

    select * from (language L inner join products P on L.code=P.language ) inner join Catalog C on P.CatalogGuid=C.CatalogGuid where L.isdefault=true
      

  2.   

    select p.*,c.CatalogName from products as p,Catalog  as  c 
    where p.CatalogGuid =c.CatalogGuid 
    and 
    c.language 
    in (select Code from  language where IsDefault=true)
      

  3.   


    谢谢,我用这个他提示DataBinding:“System.Data.DataRowView”不包含名为“Id”的属性。
    但是我gridview里加了DataKeyNames="Id"的啊,不知道什么原因
      

  4.   

    你是不是表内容错了,类别1的不同语言的CatalogGuid都一样,如果确实一样的话,你就不应该只用CatalogGuid 来判断相等,应该改为select p.*,c.CatalogName from products as p,Catalog  as  c where p.CatalogGuid =c.CatalogGuid and c.language  =p.language   and c.language in (select Code from  language where IsDefault=true) 
      

  5.   

    要么你这样吧select P.*,C.CatalogName from products P inner join Catalog C on P.CatalogGuid=C.CatalogGuid where exists (select * from language where Code=P.language and IsDefault=true)
      

  6.   


    谢谢,我放sql查询里面试过,读出来还是全部记录哦
      

  7.   

    用两个关联来做就可以了
    select a.name  as productName,c.CatalogName
    from products a
    left join language b on a.language=b.Code
    left join Catalog c on a.CatalogGuid=c.CatalogGuid
    where b.IsDefault=true