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.
| Author |
Topic |
|
cool.mugil
Starting Member
32 Posts |
Posted - 2010-03-18 : 07:26:42
|
| Hi,My table structure is like this,S.no, EmployeeID1, 12, 13, 2 4, 25, 36, 3i want to take unique employeeid with s.no.How to write the query.Please help me?My result should be like this,S.no EmployeeID 1, 13, 25, 3Thanks ,Mugil |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-18 : 07:30:56
|
| select S.no, EmployeeID from( select seq=row_number()over(partition by EmployeeID order by s.no),s.no,employeeid from tbl)t where seq=1 |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-03-18 : 07:31:39
|
| create table tst ( Sno int , EmployeeID int )goinsert into tstSELECT 1, 1union allSELECT 2, 1union allSELECT 3, 2 union allSELECT 4, 2union allSELECT 5, 3union allSELECT 6, 3go SELECT sno, employeeidFROM (SELECT ROW_NUMBER() OVER( Partition by EmployeeID order by sno) seq, * FROM tst)a WHERE seq = 1Vaibhav T |
 |
|
|
cool.mugil
Starting Member
32 Posts |
Posted - 2010-03-18 : 07:40:07
|
Thanks haroon2k9 it solved my problemquote: Originally posted by haroon2k9 select S.no, EmployeeID from( select seq=row_number()over(partition by EmployeeID order by s.no),s.no,employeeid from tbl)t where seq=1
|
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-18 : 07:40:50
|
quote: Originally posted by cool.mugil Thanks haroon2k9 it solved my problemquote: Originally posted by haroon2k9 select S.no, EmployeeID from( select seq=row_number()over(partition by EmployeeID order by s.no),s.no,employeeid from tbl)t where seq=1
welcome. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|