Baran Topal

Baran Topal


October 2024
M T W T F S S
« Feb    
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories


looper in MSSQL

baranbaran

Following this looper case, http://www.barantopal.com/technology/looper-in-c/

Now, out of curiosity, I tried to solve this in MSSQL.

ID ColX
1 3
2 3
3 6
4 5
5 2
6 2
7 9
9 11
10 1
11 13
13 14
14 12
15 19
17 18
19 20
20 16
21 22
22 21
23 23
24 23

The following SQL snippet is not the solution but it is too late here and I need to sleep 🙂
I will update this later on.


SELECT ID, ColX
FROM MyTable
WHERE NOT EXISTS (
   SELECT 1 
   FROM MyTable lkup
   WHERE lkup.ColX = MyTable.ID
) OR NOT EXISTS (
   SELECT 1 
   FROM MyTable lkup
   WHERE lkup.ID = MyTable.ColX
)
;