试试。
select  userId, username, otherdata from table where userId in (select distinct userId from table)

解决方案 »

  1.   

    select userid,username,otherdata from Utable A
    where  username in ( select top 1 username from Utable where userid=A.userid)
    and    otherdata in (select top 1 otherdata from Utable where userid=Auserid)
      

  2.   

    select userid,username,otherdata from Utable A
    where  username in ( select top 1 username from Utable where userid=A.userid)
    and    otherdata in (select top 1 otherdata from Utable where userid=A.userid)
      

  3.   

    产生两条重复的记录?用distinct时只是将userid的重复记录给去掉了,但是当同一个userid对应两个不同的username或otherdata时,就会是两条记录。特别是当有多个主键或无主键的时候,如果此表中只有一个userid做为主键的话,用distinct来处理比较好!