I’ve been having trouble coming up with a proper query to handle this situation in SQL Server.
There are two tables, Warehouse and Transfer:
Warehouse
- wh_id(PK)
- wh_name
Transfer
- transfer_id(PK)
- transfer_from(FK)
- transfer_to (FK)
I need a query to return:
- transfer_id
- transfer_from – Name, not id
- transfer_to – Name, not id
What I’ve tried so far:
SELECT T.transfer_id, WH.wh_name, T.transfer_to
FROM transfer AS T INNER JOIN warehouse AS WH
ON T.transfer_from = WH.wh_id
This only gives the name for the transfer_from not the transfer_to. I’ve had a need for a similar query but my level of SQL expertise is low and I just don’t know how to approach this problem. Any guidance is greatly appreciated.
you need to join the table
warehousetwice because you need to get the equivalent name fro two columsn in yourtransfertable.