I have a table
Assets table
Asset Id | Asset Name | Asset Type | Product Id
Transfers Table
Transfer Id | From Asset ID | To Asset Id | Product Id
I’m trying to join these table to get me
Transfer ID | From Asset Name | To Asset Name | Product Id
I used
Select *
From Transfer
Left join Asset on asset.id = from_asset_id or asset.id = to_asset_id
But I’m getting the output in different rows for the from asset name and to asset name.I want it to be in a same column not rows.
Can anyone help me, how should I query to get to my output?
2
Answers
You seem to want two joins, as in:
I am not sure why you would use
left join
here – unless the two asset columns are nullable.I made an attempt using slightly different notation from that of the accepted answer, but you could also use the following: