我有三个表:
产品表(产品ID,产品名称)
属性表(属性ID,属性名称)
产品属性表(产品ID,属性ID,属性规格)要联合查询出  产品名,产品属性,属性规格  怎么写查询语句?

解决方案 »

  1.   

    select t1.产品名称,t2.产品属性,t3.属性规格
    from 产品表 t1,属性表 t2,产品属性表 t3
    where t1.产品ID=t3.产品ID and t2.属性ID=t3.属性ID
      

  2.   

    select t1.产品名称,t2.产品属性,t3.属性规格 
    from 产品表 t1,属性表 t2,产品属性表 t3 
    where t1.产品ID=t3.产品ID and t2.属性ID=t3.属性ID
      

  3.   

    select distinct t1.产品名称,t2.产品属性,t3.属性规格 
    from 产品表 t1,属性表 t2,产品属性表 t3 
    where t1.产品ID=t3.产品ID and t2.属性ID=t3.属性ID
      

  4.   

    select t1.产品名称,t2.产品属性,t3.属性规格 
    from 产品表 t1,属性表 t2,产品属性表 t3 
    where t1.产品ID=t3.产品ID and t2.属性ID=t3.属性ID
      

  5.   

    Select 产品表.产品名称,属性表.属性名称,产品属性表.属性规格
    from 产品表 join 产品属性表 on 产品表.产品ID = 产品属性表.产品ID
    join 属性表 on 属性表.属性ID = 产品属性表.属性ID和楼上的大同小异~
      

  6.   

    select A,B,C
    from
    (
    select *,Row_number()over(partition by A order by A)cnt
    from
    (
    select N'手机' as A,    N'宽度' as B,  N'10' c
    union all
    select N'手机' as A,    N'长度' as B,  N'15' c
    union all
    select N'电脑' as A,    N'重量' as B,  N'22' c
    union all
    select N'电脑' as A,    N'颜色' as B,  N'黑' c
    )A)A
    where cnt =1
      

  7.   


    select distinct 产品表.产品名称.......