-1

I'm trying to combine these queries but having no luck. I need to be able to maintain all columns in the result. How can I do this?

These are my queries:

SELECT c.CustomerID, EmailAddress, LastName, FirstName, Line1 AS BillLine1, Line2
       AS BillLine2, City AS BillCity, State AS BillState, ZipCode AS BillZip FROM 
       Customers c JOIN Addresses ON c.BillingAddressID = Addresses.AddressID 

SELECT Line1 AS ShipLine1, Line2 AS ShipLine2, City AS ShipCity, State AS ShipState,
       ZipCode AS ShipZip FROM Customers b JOIN Addresses ON b.ShippingAddressID = 
       Addresses.AddressID;
Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
CandyCane
  • 29
  • 5
  • I really hope you are not planning on use a union on that query... – Cristobal De Leon Oct 28 '13 at 22:26
  • A UNION wouldn't work, that's why I'm here asking for help. Besides, a UNION requires the same amount of columns and if I used a UNION, it removes the columns in the second query. – CandyCane Oct 28 '13 at 22:29
  • At least as far as I know.... – CandyCane Oct 28 '13 at 22:30
  • Combine defined: Result set combined. It keeps the columns separate, but the output would be something like CustID, Email, LName,FName, BillLine1, BillLine2, BillCity, BillState,BillZip, ShipLine1, ShipLine2, ShipCity,ShipState, ShipZip(all as individual columns) – CandyCane Oct 28 '13 at 22:31
  • You're right, I'm sorry got confused on how Union worked! – Cristobal De Leon Oct 28 '13 at 22:35

1 Answers1

3

Maybe something like this? S

ELECT
    c.CustomerID,
    EmailAddress,
    LastName,
    FirstName,
    a1.Line1 AS BillLine1,
    a1.Line2 AS BillLine2,
    a1.City AS BillCity,
    a1.State AS BillState,
    a1.ZipCode AS BillZip,
    a2.Line1 AS ShipLine1,
    a2.Line2 AS ShipLine2,
    a2.City AS ShipCity,
    a2.State AS ShipState,
    a2.ZipCode AS ShipZip
FROM
       Customers c
       JOIN Addresses a1 ON c.BillingAddressID = a1.AddressID
       JOIN Addresses a2 ON c.ShippingAddressID = a2.AddressID
Lajos Veres
  • 13,595
  • 7
  • 43
  • 56