190k views
1 vote
"3 USE Createguitarshop DATABASE

Write a SELECT statement that joins the
Customers table to the Addresses table
and returns these columns: FirstName,
LastName, Line1, City, State, ZipCode.
Return one row for each customer, but only return addresses that are the shipping address for a customer."

User Minh Kha
by
8.9k points

1 Answer

1 vote

Final answer:

To join the Customers and Addresses tables and return specific customer name and shipping address details, a SELECT statement with a JOIN condition based on the ShippingAddressId and filtered by address type 'Shipping' is used.

Step-by-step explanation:

The question pertains to writing an SQL SELECT statement to join two tables, Customers and Addresses, within a database for a guitar shop. This query aims to return specific columns that include customer names and their shipping addresses. To achieve the described result, you can write a query like the following:

SELECT Customers.FirstName, Customers.LastName, Addresses.Line1, Addresses.City, Addresses.State, Addresses.ZipCode
FROM Customers
JOIN Addresses ON Customers.ShippingAddressId = Addresses.AddressId
WHERE Addresses.AddressType = 'Shipping';

This SQL statement selects the FirstName and LastName from the Customers table and the Line1, City, State, and ZipCode from the Addresses table. It joins the two tables based on a common key, assumed here to be Customers.ShippingAddressId and Addresses.AddressId, and filters for addresses where the type is specifically for shipping.

User Newlife
by
8.3k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.