Baran Topal

Baran Topal


September 2022
M T W T F S S
« Feb    
 1234
567891011
12131415161718
19202122232425
2627282930  

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
)
;