Table:
create table tbl_test
(
col1 int,
col2 int
);
Records:
INSERT INTO tbl_test VALUES(111,112),
(112,113),
(113,114),
(114,111),
(115,116),
(117,118),
(118,119),
(111,130),
(120,121),
(122,123),
(123,111),
(124,111);
Query: I want to find the complete chain col1 and col2 in the form of 111->112->113->114->111
(This is complete chain because it starts with 111
and end with 111
).
Expected Output 2:
col1 col2
-------------
111 112
112 113
113 114
114 111