我試圖從oracle表中選擇*,但只在user_id是唯一的地方。根據Oracle中不同的用戶標識選擇所有內容
我想這:
select distinct user_id from users; -- which worked
我想顯示的一切,所以當我把:
select distinct user_id, * from users; -- i get a syntax error
我怎麼能完成他的?
我試圖從oracle表中選擇*,但只在user_id是唯一的地方。根據Oracle中不同的用戶標識選擇所有內容
我想這:
select distinct user_id from users; -- which worked
我想顯示的一切,所以當我把:
select distinct user_id, * from users; -- i get a syntax error
我怎麼能完成他的?
select distinct user_id, users.* from users;
這應該這樣做。 – CristiC
與'SELECT DISTINCT * FROM users'不一樣嗎? –
謝謝,我發現這個問題,它是在一個user_ids之後的一個愚蠢的空間。它在Oracle中將它們視爲獨一無二的,而不是在Sql Sever中。謝謝! –
select * from users where users.primary_key IN
(select primary_key FROM users GROUP BY user_id HAVING count(*) = 1)
這隻會選擇不與其他行共享user_ids記錄。
呃,你的查詢沒有意義。如果給定的user_id有多行...您希望返回什麼? –
我不在乎它返回哪裏,我只想要一個。 –