<a href="ViewProduct.asp?id=<%=rs("id")%>" target="_blank"><font color="red"><%=rs("name")%></font></a>
这一句不对,你的SQL语句只有一列:NAME,没有ID这一列。

解决方案 »

  1.   

    sql="select distinct name,id from products where star='1'"我加上选择出来的记录中就有NAME重复的了呀
      

  2.   

    同意按鈕JJ,
    改SQL好了select distinct id,name from products
      

  3.   

    那就这个啦:
    select t.name,products.id from (select distinct name from products) t
    left join products on t.name=products.name order by products.id
      

  4.   

    那就这个啦:
    select t.name,products.id from (select distinct name from products) t
    left join products on t.name=products.name order by products.id
      

  5.   

    不好意思,还得加上where stat='1'。这样
    select t.name,products.id from (select distinct name from products where star='1') t
    left join products on t.name=products.name order by products.id desc
      

  6.   

    我 用sql="select distinct id,name from products where star='1'"
    现在程序正常,选择出了三条记录,应该是两条的,我的目的是NAME不重复的用sql="select * from products where star='1' order by sn DESC"
    程序出错,主要是因为缺少ID
    但是程序测试中选择出了两条正确的记录,那真正正确的语句应该是什么呀!
      

  7.   

    选出来的记录中有两个name相同的?
    不可能,是不是name中空格的问题,那你在两边加上ltrim(rtrim())啦!
      

  8.   

    你用select distinct name from products where star='1'结果有几条?
      

  9.   

    那你这样吧
    select t.name,max(products.id) from (select distinct name from products where star='1') t
    left join products on t.name=products.name order by products.id desc
    group by t.name