select id,user_id,name
from aa
where userid in
(
select userid from aa group by userid having id = min(id)
)
;假设表是aa
from aa
where userid in
(
select userid from aa group by userid having id = min(id)
)
;假设表是aa
select id, user_id, name
from aa
where id = user_id这样最简单,但肯定不是你要的.
,user_id
,name
from tablename
where rownum<=2; ID USERID NAME
--- ------ ----
1 1 a
2 2 b你是一次要取两行么? 用rownum 来作比较快 而且提高查询速度
from aa
group by user_id
haveing (count(user_id) > 1)