通过 表中的一个字段(该字段不唯一) 获取到了几条数据 但现在我只想要其中的一条怎么办? 主键自增 数据库不可修改select t.*, t.rowid from flow_entrust t where 代理人='张三'         委托ID               委托人        委托人ID        代理人        代理人ID    状态
1 136 administrator 258      张三          330          1
2 137   郭四          331           张三    330          1
现在我想要获取 1 里面委托人的值 怎么办?

解决方案 »

  1.   

    select top 1 t.*, t.rowid from flow_entrust t where 代理人='张三'  
      

  2.   


    同问。如果是取小的可以用top 1 ,并排序order by  委托ID
    select top 1 委托人 flow_entrust t where 代理人='张三'  order by 委托人ID  asc
      

  3.   

    --取相对较小的ID
    SELECT *FROM flow_entrust a WHERE id in(select min(id)from flow_entrust b where a.代理人=b.代理人)
    where a.代理人='张三'
    --取相对较大的ID
    SELECT *FROM flow_entrust a WHERE id in(select max(id)from flow_entrust b where a.代理人=b.代理人)
    where a.代理人='张三'