Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
SQL help? Trying to join two queries.?
I'm having an issue joining two queries(or unioning them) or maybe just making it one big query. I have:
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 b.CustomerID, EmailAddress, LastName, FirstName, Line1 AS ShipLine1, Line2 AS ShipLine2, City AS ShipCity, State AS ShipState, ZipCode AS ShipZip
FROM Customers b JOIN Addresses c ON b.ShippingAddressID = c.AddressID;
However, when I use union, it removes the columns from the second select statement that I need(shiplin1, shipline2, shipcity, shipstate, and shipzip). How can I maintain these columns while adding them to the first query??
2 Answers
- Jeff PLv 78 years agoFavorite Answer
You need another JOIN. Join Addresses again (using a different name) and you can get the shipping address for each customer.
- godfatherofsoulLv 78 years ago
Try adding constant placeholder values in the first query:
...,'No Shipping Address' AS ShipLine1,...
and in the 2nd query:
...,'No Billing Address' AS BillLine1,...