| How to
construct a correlated derived table query? |
|
The following
sample illustrates the derived table in the select list which
is also a correlated subquery:
USE pubs
SELECT EmployeeID=emp_id, FirstName=fname,
LastName=lname, JobID=job_id,
(SELECT COUNT(*) FROM employee e2
WHERE e2.lname <= e1.lname AND e2.job_id = 7) AS SeqNo
FROM employee e1
WHERE job_id = 7
ORDER BY LastName
|
| The Best SQL Server
Training in the World |
|