I am trying to select * from an oracle table, but only where user_id are unique.
i tried this:
select distinct user_id from users; -- which worked
i want to display EVERYTH开发者_如何学编程ING, so when i put:
select distinct user_id, * from users; -- i get a syntax error
how can i accomplish his?
select distinct user_id, users.* from users;
select * from users where users.primary_key IN
(select primary_key FROM users GROUP BY user_id HAVING count(*) = 1)
This will only select records that do not share user_ids with other rows.
精彩评论