1.11: Join

In this lesson, you'll learn how to query data from multiple tables. This short video will introduce the concept of an "inner join," which is the type of join you'll be using below. You can also read more about joining tables in T-SQL by clicking here.

Start by copying and pasting this code into a query in Visual Studio. This will populate the table you created in the previous lesson.

SET IDENTITY_INSERT Purchases ON
INSERT Purchases (PurchaseID, ProductID, CustomerID, Quantity) 
    VALUES (1, 1, 1, 5),
    (2, 1, 2, 5),
    (3, 2, 4, 3);

This is what the resulting table should look like:

Now, write a query that will return a table containing the customer's first names that have a PurchaseID. You'll have to use an "INNER JOIN" to accomplish this. Remember that you are also working with multiple tables, so consider which tables have the data you are querying for. Finally, think about what columns these tables have in common.

The resulting table output from your query should look like this:

To see the solution for this challenge, click on 1.12 Solutions. For additional challenges, please continue to Part Three.

Last updated