Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to get desired output Expand / Collapse
Author
Message
Posted Friday, February 15, 2013 2:14 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, April 09, 2014 4:18 AM
Points: 277, Visits: 288
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 | Articles
Post #1420438
Posted Friday, February 15, 2013 2:35 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 08, 2014 6:13 AM
Points: 1,694, Visits: 19,550

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)



____________________________________________________

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1420451
Posted Friday, February 15, 2013 2:39 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, April 09, 2014 4:18 AM
Points: 277, Visits: 288
Thank you so much.........

Thanks.......
-----------------------------------
My Blog | Articles
Post #1420453
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse