Hello,
There is a table as follows:
create table #tblMain(ID int, MyID int, FromID int, ToID int)
insert into #tblMain(ID, MyID, FromID, ToID) values(7, 5, 99, 353)
insert into #tblMain(ID, MyID, FromID, ToID) values(6, 5, 399, 398)
insert into #tblMain(ID, MyID, FromID, ToID) values(5, 5, 346, 543)
insert into #tblMain(ID, MyID, FromID, ToID) values(4, 5, 353, 400)
insert into #tblMain(ID, MyID, FromID, ToID) values(3, 5, 393, 403)
insert into #tblMain(ID, MyID, FromID, ToID) values(2, 5, 307, 306)
insert into #tblMain(ID, MyID, FromID, ToID) values(1, 5, 400, 1238)
select * from #tblMain
drop table #tblMain
For example, you would like to find out where the ToID valueof 1238 originated from?
The answer is 99
or the originator of ToID value of 306 is 307
How is this done in sql please?
Thanks