AdventureWorks Database: Retrieve the territory name and BusinessEntityID
SQL Query - AdventureWorks: Exercise-41 with Solution
41. From the following tables write a SQL query to retrieve the territory name and BusinessEntityID. The result set includes all salespeople, regardless of whether or not they are assigned a territory.
Sample table: Sales.SalesTerritory
Sample table: Sales.SalesPerson
Sample Solution:
SELECT st.Name AS Territory, sp.BusinessEntityID
FROM Sales.SalesTerritory AS st
RIGHT OUTER JOIN Sales.SalesPerson AS sp
ON st.TerritoryID = sp.TerritoryID ;
Sample Output:
territory |businessentityid| --------------+----------------+ | 274| Northeast | 275| Southwest | 276| Central | 277| Canada | 278| Southeast | 279| Northwest | 280| Southwest | 281| Canada | 282| Northwest | 283| Northwest | 284| | 285| Australia | 286| | 287| Germany | 288| United Kingdom| 289| France | 290|
SQL AdventureWorks Editor:
Practice Online
Contribute your code and comments through Disqus.
Previous: Fetch product names, salesorderIDs using INNER JOIN.
Next: Retrieve name and city of the employees.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join