Getting unique combination of rows in SQL??
-
I have a requirement as in below
DECLARE @TEST TABLE (X VARCHAR(10),Y VARCHAR(10))
insert into @TEST values ('A','B'),('C','D'),('E','F'),('B','A'),('D','C'),('F','E')
SELECT A.* FROM @TEST A, @TEST B WHERE A.X = B.y gives X Y A B C D E F B A D C F E But I have to get only the combination (AB or BA) ,(CD or DC),(EF or FE) in my select statement. In my sql we have some thing called DistinctRow.. What is it in SQL ..Pelase help ..urgent..
-
I have a requirement as in below
DECLARE @TEST TABLE (X VARCHAR(10),Y VARCHAR(10))
insert into @TEST values ('A','B'),('C','D'),('E','F'),('B','A'),('D','C'),('F','E')
SELECT A.* FROM @TEST A, @TEST B WHERE A.X = B.y gives X Y A B C D E F B A D C F E But I have to get only the combination (AB or BA) ,(CD or DC),(EF or FE) in my select statement. In my sql we have some thing called DistinctRow.. What is it in SQL ..Pelase help ..urgent..
-
I have a requirement as in below
DECLARE @TEST TABLE (X VARCHAR(10),Y VARCHAR(10))
insert into @TEST values ('A','B'),('C','D'),('E','F'),('B','A'),('D','C'),('F','E')
SELECT A.* FROM @TEST A, @TEST B WHERE A.X = B.y gives X Y A B C D E F B A D C F E But I have to get only the combination (AB or BA) ,(CD or DC),(EF or FE) in my select statement. In my sql we have some thing called DistinctRow.. What is it in SQL ..Pelase help ..urgent..
here it is
DECLARE @TEST TABLE (X VARCHAR(10),Y VARCHAR(10))
insert into @TEST values ('A','B')
insert into @TEST values ('C','D')
insert into @TEST values ('E','F')
insert into @TEST values ('B','A')
insert into @TEST values ('D','C')
insert into @TEST values ('F','E')SELECT A.X
,(
select top 1 b.y from @test as b where b.y > a.x and b.x a.x and b.x
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post. -
here it is
DECLARE @TEST TABLE (X VARCHAR(10),Y VARCHAR(10))
insert into @TEST values ('A','B')
insert into @TEST values ('C','D')
insert into @TEST values ('E','F')
insert into @TEST values ('B','A')
insert into @TEST values ('D','C')
insert into @TEST values ('F','E')SELECT A.X
,(
select top 1 b.y from @test as b where b.y > a.x and b.x a.x and b.x
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post. -
I was looking for some key word like distinctrow in MYSQL.. dont we have any thing like that in SQL.
-
I was looking for some key word like distinctrow in MYSQL.. dont we have any thing like that in SQL.