You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Instructions/Labs/07-combine-query-results.md
+4-44Lines changed: 4 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,19 +134,7 @@ Now you will write a table-valued function to return the product category and qu
134
134
135
135
1. Run the query and view the results.
136
136
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
150
138
151
139
Use the following code to create a table-valued function that retrieves address details for a given customer:
152
140
@@ -163,39 +151,11 @@ RETURN
163
151
164
152
Now write a query that returns every customer ID and company name along with all of the address fields retrieved by the function.
165
153
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.
169
155
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
197
157
198
-
### Challenge 2
158
+
This section contains a suggested solution for the challenge query.
0 commit comments