I have a table that looks like the following:
ID Customer Name LinkedID
1 A X
2 B Y 1
3 C Z 2
I need to write a query that will:
1- For each ID (1,2,3)
2- If there is a LINKEDID defined (2,3 have links)
3- If the CUSTOMER of the LINKEDID is A
4- Return record for that ID
So in the above example it would do something like:
- ID's 2,3 have LinkedID's specified
- ID2 links to #1 which is customer A (good) return ID2
- ID3 links to #2 which is customer B (bad)
So the end result would be ID2.
SELECT * FROM TABLE WHERE LINKED <> NULL // this will get me the list
? But now how do I iterate over each of the results and compare the customers?
Any help would be much appreciated. Thanks,