我试图从oracle表中选择*,但仅限于user_id是唯一的。
我试过这个:
select distinct user_id from users; -- which worked
我想要显示一切,所以当我把:
select distinct user_id, * from users; -- i get a syntax error
我怎么能完成他的?
答案 0 :(得分:9)
select distinct user_id, users.* from users;
答案 1 :(得分:2)
select * from users where users.primary_key IN
(select primary_key FROM users GROUP BY user_id HAVING count(*) = 1)
这只会选择不与其他行共享user_ids的记录。