Skip to content

Commit 160d9e6

Browse files
Update 07-combine-query-results.md
1 parent cecd77c commit 160d9e6

1 file changed

Lines changed: 4 additions & 44 deletions

File tree

Instructions/Labs/07-combine-query-results.md

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,7 @@ Now you will write a table-valued function to return the product category and qu
134134

135135
1. Run the query and view the results.
136136

137-
## Challenges
138-
139-
Now it's your turn to use set operators.
140-
141-
> **Tip**: Try to determine the appropriate code for yourself. If you get stuck, suggested answers are provided at the end of this lab.
142-
143-
### Challenge 1: Find non-managerial salespeople
144-
145-
Each customer has an allocated employee as a salesperson, indicated by the **SalesPerson** field in the **SalesLT.Customer** table. Additionally, some employees are managers, indicated by their employee ID being listed as the **ManagerID** for other employees in the **SalesLT.Employee** table.
146-
147-
You must write a query that returns the ID and name for each employee who is assigned as a salesperson for a customer but who is <u>not</u> a manager.
148-
149-
### Challenge 2: Return addresses for each customer
137+
## Challenge
150138

151139
Use the following code to create a table-valued function that retrieves address details for a given customer:
152140

@@ -163,39 +151,11 @@ RETURN
163151

164152
Now write a query that returns every customer ID and company name along with all of the address fields retrieved by the function.
165153

166-
## Challenge Solutions
167-
168-
This section contains suggested solutions for the challenge queries.
154+
> **Tip**: Try to determine the appropriate code for yourself. If you get stuck, a suggested answer is provided below.
169155

170-
### Challenge 1
171-
172-
```sql
173-
SELECT EmployeeID, EmployeeName
174-
FROM SalesLT.Employee
175-
WHERE EmployeeName IN (SELECT SalesPerson FROM SalesLT.Customer)
176-
EXCEPT
177-
SELECT EmployeeID, EmployeeName
178-
FROM SalesLT.Employee
179-
WHERE EmployeeID IN (SELECT ManagerID FROM SalesLT.Employee)
180-
ORDER BY EmployeeID;
181-
```
182-
183-
*or*
184-
185-
```sql
186-
SELECT DISTINCT e.EmployeeID, e.EmployeeName
187-
FROM SalesLT.Employee as e
188-
JOIN SalesLT.Customer as c
189-
ON e.EmployeeName = c.SalesPerson
190-
EXCEPT
191-
SELECT DISTINCT m.EmployeeID, m.EmployeeName
192-
FROM SalesLT.Employee AS e
193-
JOIN SalesLT.Employee AS m
194-
ON e.ManagerID = m.EmployeeID
195-
ORDER BY EmployeeID;
196-
```
156+
## Challenge Solution
197157

198-
### Challenge 2
158+
This section contains a suggested solution for the challenge query.
199159

200160
```sql
201161
SELECT c.CustomerID, c.CompanyName, a.*

0 commit comments

Comments
 (0)