Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can i select all values from table w/o duplicates?

Author  Topic 

iNko
Starting Member

19 Posts

Posted - 2012-12-09 : 09:18:14
Hello, i have a table witch has 3 columns:

Table1
ID GROUP_NAME USER
1 Administrator John
2 Administrator Dave
3 Moderator James
4 IT Tom

I want to show all group names, without showing duplicates, can i do this?

Example:
SELECT GROUP_NAME FROM Table1

Result:
Administrator
Administrator
Moderator
IT

What i want to display:
Administrator
Moderator
IT

Please help

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-09 : 10:16:19
[code]SELECT distinct GROUP_NAME FROM Table1[/code]
Or you want to show individual name per group

[code]Select * from
(SELECT *,ROW_NUMBER() OVER(PARTITION BY GROUP_NAME ORDER BY USER)as Seq
FROM Table1
)P
Where Seq = 1[/code]
Go to Top of Page

iNko
Starting Member

19 Posts

Posted - 2012-12-09 : 10:47:13
Thank you!
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-09 : 11:04:41
NP
Go to Top of Page
   

- Advertisement -