Reputation: 459
I think the screenshot of the query is pretty much self-explanatory.
What I need, is simply to get 2 addresses from CustomerAddresses table instead of only 1 like in this example. 1 for ShippingAddress and the other for BillingAddress.
It sounds like It's quite easy to solve this but obviously I'm missing something. Thanks in advance..
Upvotes: 0
Views: 49
Reputation: 174329
You need to join the table that contains the addresses twice. Once for ShippingAddressID
and once for BillingAddressID
:
SELECT
...
ShippingAddress.Address as 'ShippingAddress',
BillingAddress.Address as 'BillingAddress',
...
FROM
...
INNER JOIN CustomerAddresses as ShippingAddress
ON Orders.ShippingAddressID = ShippingAddress.CustomerAddressID
INNER JOIN CustomerAddresses as BillingAddress
ON Orders.BillingAddressID = BillingAddress.CustomerAddressID
Upvotes: 2