开发者

Select everything, based on distinct USER ID in Oracle

开发者 https://www.devze.com 2023-03-31 06:48 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消