A table will be having main part and sub part , again main part will be sub part of another main part and it may go till end .
Main Part ------Sub Part
------------------------
A123 --------------B123
B123 --------------C123
C123 --------------D123
A123 --------------B123
X123 --------------Y123
Y123 --------------Z123
From image above when I put D123 in where condition I need A123 as output .
Query -->
Select * from table where Sub Part = 'D123'
*Output -->*A123
In the same way when I put Z123 in where condition I need to get X123 where.
Query -->
Select * from table where Sub Part = 'X123'
*Output -->*Z123
Expected Query as answer --> I need a query such that it will fetch last main part in the chain