Reputation: 645
The above table has recursive relationship ie. the crfor
column has reference to resourceid
column.
So the number 1
in the crfor
column means resourceid = 1
.How should I change my query to make crforname
column (dynamic column) display the proper name Arjun
instead of Ashok
?
I used the query below to get the result above. You can ignore the other table call PCR in the query
select t1.*,t2.pcrname,t1.ResourceName AS crforName from
Resource t1 left join Pcr t2 on t1.Pcrid=t2.pcrid
where t1.contractid=1
Upvotes: 0
Views: 714
Reputation: 45741
Try adding a self join on the Resource
table joining the ResourceId
to the CrFor
:
select t1.*,t2.pcrname,t3.ResourceName AS crforName from
Resource t1 left join Pcr t2 on t1.Pcrid=t2.pcrid left join Resource t3 on t1.CrFor = t3.ResourceId
where t1.contractid=1
Upvotes: 2