select distinct ID,u_id ,U_Name,Pass from table
Group by u_id 

解决方案 »

  1.   

    select  * from table A
    where A.U_ID In
    (select distinct u_id from table B)
      

  2.   

    同意wangzh,你在distinct后面写上所有字段不就行了?
      

  3.   

    select * from tableA
    where id in (select max(id) from tableA group by u_id)
      

  4.   

    你的问题有用吗(有这样的应用吗)?
    我只能用临时表做.你可以调用存储过程得到数据.select * into #temp1
    from table 
    where 1=2 //目的是为了得出一个空临时数据表insert #temp1(U_ID,U_Name,Pass)
    select distinct u_id,'','' 
    from tableupdate #temp1 set a.u_name=b.u_name,a.pass=b.pass
    from #temp1 a,table b
    where a.u_id=b.u_idselect * from #temp1//drop table #temp1
      

  5.   

    如果想得出一个表中有只有一条记录的字段,在MSSQL中可以这么写
    select U_ID from table
    group by  U_ID
    having count(A)=1那么想找出所有的记录值,可以这么写
    select * from table where u_id in (select U_ID from table
    group by  U_ID  having count(A)=1) 
      

  6.   

    select distinct ID,u_id ,U_Name,Pass from table
    Group by u_id 根本行不通!select  * from table A
    where A.U_ID In
    (select distinct u_id from table B) 
    又错误的理解了我的意思。只有一张表靠
    select * from tableA
    where id in (select max(id) from tableA group by u_id) 
    果来好使,谢了KingSunShaafeisky和txinfo的还没有试过,以上各位谢了