select distinct a.*
from Category a inner Join Info as b
  on a.id=b.CategoryId

解决方案 »

  1.   

    select * from
    (
    select a.id,a.categorname,b.categoryid,b.infoname,b.id as id1 from Category a,info b
    where a.id=b.categoryid
    ) a where 
    (select count(1) from
    (
    select a.id,a.categorname,b.categoryid,b.infoname,b.id as id1 from Category a,info b
    where a.id=b.categoryid
    ) b where a.id=b.id and a.id1<b.id1)<1
      

  2.   

    select a.* , b.CategoryId , b.InfoName
    from Category a 
    left outer join Info b on a.id=b.CategoryId
      

  3.   

    try:
    select info.ID,Category.CategoryName,info.InfoName
    from Category,info
    where info.CategoryId *=Category.Id
      

  4.   

    SELECT DISTINCT a.*
    FROM Category a LEFT OUTER JOIN
          Info b ON a.Id = b.CategoryId只是显示类别名称,如果只显示类别名称直接select * from Category就可以了
    而我还要求显示其中一个产品名称,
    多谢大家了!
      

  5.   

    declare @Category table(Id int,CategoryName varchar(12))
    insert @Category select 1,'AA' union select 2,'BB'declare @info table(Id int,CategoryId int,InfoName varchar(10))insert @info select 1,1,'a' union select 2,1,'b' union select 3,2,'aa' union select 4,2,'bb'
    union select 5,2,'cc'select a.CategoryId,b.CategoryName,max(InfoName) from @info a,@Category b
    where a.CategoryId = b.id group by CategoryId,b.CategoryName
    /*CategoryId  CategoryName            
    ----------- ------------ ---------- 
    1           AA           b
    2           BB           cc
    */