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 |
|
SunnyIngulia
Starting Member
2 Posts |
Posted - 2010-10-12 : 06:02:59
|
| I am using SQL Server 2008. So according to the task: if the table consists records like this:id1 name1 id2 name21 a 2 b2 b 1 a1 a 3 c3 c 1 a2 b 3 cthe result must be:id1 name1 id2 name21 a 2 b1 a 3 c2 b 3 c So as you see rows 1 a 2 b and 2 b 1 a must represent as the same(dublicate) How can I exclude rows that consist the same data in different order?SunnyIngulia |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-12 : 09:03:13
|
| [code]declare @tbl table(id int identity,id1 char(40),name1 char(40),id2 char(40),name2 char(40))insert into @tblselect '1', 'a', '2', 'b'union allselect '2', 'b', '1', 'a'union allselect '1', 'a', '3', 'c'union allselect '3', 'c', '1', 'a'union allselect '2', 'b','3', 'c';with cteas(select *,row_number()over(partition by sm order by id)rid from(select sum(rid)sm,id from( select *, dense_rank()over(order by col)rid from ( select * from @tbl)u unpivot (col for columns in(id1,name1,id2,name2))v )Tgroup by id )T1)select t.* from cte inner join @tbl t on t.id=cte.id where rid=1 order by cte.id[/code]PBUH |
 |
|
|
SunnyIngulia
Starting Member
2 Posts |
Posted - 2010-10-12 : 10:19:50
|
Thanks a lot! It is geat! SunnyIngulia |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-12 : 11:16:12
|
quote: Originally posted by SunnyIngulia Thanks a lot! It is geat! SunnyIngulia
My pleasure PBUH |
 |
|
|
|
|
|
|
|