0

screenshot of the query

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..

4

1 回答 1

2

您需要将包含地址的表加入两次。一次ShippingAddressID又一次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
于 2013-04-12T10:49:09.600 回答