how to get desired output

  • create table tbltests(id int ,id1 int)

    insert into tbltests(id,id1) values

    (1,2),(2,1),(3,null),(4,5),(5,4)

    I want if row like

    1 2

    2 1

    then only one row selected

    as 1 2.

    if

    3 null

    then it also should fetch with select query.

    Please reply.

    Output should like

    1 2

    3 null

    4 5

    Thanks.......
    -----------------------------------
    My Blog[/url] | Articles

  • SELECT t1.id,t1.id1

    FROM tbltests t1

    WHERE NOT EXISTS(SELECT * FROM tbltests t2

    WHERE t2.id = t1.id1

    AND t2.id1 = t1.id

    AND t2.id < t2.id1)

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537
  • Thank you so much.........

    Thanks.......
    -----------------------------------
    My Blog[/url] | Articles

Viewing 3 posts - 1 through 2 (of 2 total)

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