SQL Server Inner Join Example


Here is a simple Join example in SQL Server. Based on the following relationship in the Adventure Works database, suppose you want to retrieve data from the Person table for Store Contacts who are Purchasing Managers.

AdventureWorksJoin

This is a snapshot of the data contained in each individual table:

AdventureWorksTables

Here is the SQL join statement to retrieve data from the Contact table for Store Contacts that are Purchasing Managers:

select PC.* from Person.Contact PC
join Sales.StoreContact SC on PC.ContactID = SC.ContactID
join Person.ContactType CT on SC.ContactTypeID = CT.ContactTypeID
where CT.Name = 'Purchasing Manager'
order by PC.LastName

Here is a snapshot of the results of the join:

AdventureWorksJoinResults

No comments:

Post a Comment