SELECT EmployeeID, (FirstName + ' ' + LastName) AS Name FROM Employees WHERE EmployeeID IN (SELECT EmployeeID FROM EmployeeTerritories WHERE TerritoryID=01581)

Things You Should Know About Subqueries:
- They are not the most efficient performance wise
- You can only retrieve a single column in the subquery, retrieving multiple columns will throw an error
SELECT CategoryName, (SELECT AVG(UnitPrice) FROM Products WHERE CategoryID = 1) AS AvgPrice FROM Categories WHERE CategoryID = 1

No comments:
Post a Comment