Distinct value from the sets?

  • DECLARE @test-2 TABLE (a int, b int)

    insert into @test-2 values (1,2)

    insert into @test-2 values (2,1)

    insert into @test-2 values (3,1)

    insert into @test-2 values (4,1)

    insert into @test-2 values (1,4)

    output will be in given format

    1,2

    3,1

    4,1

  • Is there a question here?

  • DECLARE @test-2 TABLE (a int, b int)

    insert into @test-2 values (1,2)

    insert into @test-2 values (2,1)

    insert into @test-2 values (3,1)

    insert into @test-2 values (4,1)

    insert into @test-2 values (1,4)

    This is my table and rows, now i want to the distinct value from this table. Eg col a value some time is repeated in col b and vice versa.

    set like this

    1,2

    2,1

    from this i want only one output, either 1,2 or 2,1 not both?

  • Something like this?

    DECLARE @test TABLE (a int, b int)

    insert into @test values (1,2)

    insert into @test values (2,1)

    insert into @test values (3,1)

    insert into @test values (4,1)

    insert into @test values (1,4)

    insert into @test values (2,2)

    SELECT a, b FROM @test

    EXCEPT (

    SELECT t1.a, t1.b FROM @test t1 JOIN @test t2

    on t1.a = t2.b and t1.b = t2.a

    WHERE t1.a > t1.b

    )

    John

  • Thansk John. It works fine

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply