本帖最后由 ibatsiSpring 于 2009-09-02 00:41:07 编辑

解决方案 »

  1.   

    我觉得这是最普通的主外键关联,不应该用distinct,楼主能否给出个例子来,比如部门和员工间的关系,或学生和课程的关系等。
      

  2.   

    cname重复的话是很正常的啊!B表中的数据cid应该是主键,也就是说是唯一性的字段。当你用select cname from A,B 
         where A.pid=B.pid 
    查询出来的结果是对的,说明数据和SQL也是对的,你用distinct只是去重而已。当然了,你想要不重复的数据则另当别论。
      

  3.   

    select cname
    from(
    select cname,row_number() over(partition by cname) rn from A,B 
    where A.pid=B.pid)
    where rn=1