I have a two tables,Transaction and Master. The transaction table shows a from and to activity id. The master shows the activity id and a name. The from and to id use the same master table to associate the activity id and name. What I would like to do is take the distinct from and to values and display them with the associated name.
The original query was
select distinct a.from, a.to from Transaction a
What I need is something where a.from is followed by b.name and a.to is followed by b.name
I know that I have to have a join but I need the join to apply to each of the distinct a.values.
In concept I would like to do 2 joins with one on each of the a.values but I am not sure how to delineate the from and to values.
select distinct a.from, f.name as FromName, a.to, t.name as ToName
from Transaction a
join Master F on a.from = f.id
join Master T on a.to = f.id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With