try select * from product
where id in 
(select min(id) as id from product
group by company,   product,  categoryid)

解决方案 »

  1.   


    select a.*
    from product a join
         (select min(id) as id from product where categoryid=2 group by company) b
         on a.id=b.id
      

  2.   

    呵,终于被我想出来了,不过总觉得有点牵强,不过比较急用,先用着,希望大家帮我改进,
    SELECT compay,id,product FROM product WHERE id in (select max(id) as id from product where categoryID=2 group by company)
    虽然没试过楼上二位的方法,但还是要谢谢
    希望你们还能把我的方法改进一下,
      

  3.   

    楼上的你可以把in改变exist,不明白你的具体意思,你想要显示的product没有什么特别的要求吗
    select company, max(id) as id ,max(product)  as  product 
    from  product
    where categoryid=2
    group by company
    order by  company
      

  4.   

    SELECT compay,id,product FROM product WHERE id in (select max(id) as id from product where categoryID=2 group by company)
    这个应该是对的,
    不过至于楼上的,不清楚