sql2="select distinct a.id  as id from subjectInfo b,schoolInfo a where b.subjectId = '" + subjectId + "' and a.id=b.schoolInfoId  "; 
result2 = dbm.runSqlForQuery(sql2);String id=result.getString("id");

解决方案 »

  1.   

    完整代码是这样:         sql="select distinct b.name,b.id,b.content,b.countryId, c.content countryName from subjectInfo a,schoolInfo b,baseInfo c where a.subjectId = '" + subjectId + "' and b.id=a.schoolInfoId and b.countryId=c.id order by c.content,b.name ";        beans.Result result1 = null;
            result1 = dbm.runSqlForQuery(sql,currPageNo,8);
                
                String name=null;
                String schoolId=null;
        String countryId=null;
        String countryName=null;      
                String schoolBrief=null;   
                 while(result1.next())
    {
    name = result1.getString("name");
    schoolId = result1.getString("id");
    schoolBrief = result1.getString("content");
    countryId = result1.getString("countryId");
    countryName = result1.getString("countryName");

              %>
         <img src="../images/arrow3.gif" width="4" height="4" vspace="8" hspace="8" align="absmiddle">
    <a href="/yahoo/search_last.jsp?schoolId=<%=schoolId%>" target="blank"><%=name%>(<%=countryName%>)</a> 
        <blockquote>  <span class="grayfont"><%=beans.PubBean.nullStr(schoolBrief)%></span></blockquote>    <% }%>希望通过加distinct来限制查询结果唯一性,但显示NULL。
    如果去掉distinct,则查找结果不唯一,但能正确显示。
      

  2.   

    加distinct的SQL语句在ORACLE中运行正确。
      

  3.   

    distinct只能对一列操作
    不能对多列操作