
May 27th, 2009, 11:13 AM
|
|
Registered User
|
|
Join Date: Feb 2009
Posts: 3
Time spent in forums: 40 m 8 sec
Reputation Power: 0
|
|
|
Inner Join problem
Hi there,
I'm having abit of trouble creating a query that takes a result set and adds an additional column (or replaces it) using either JOIN or SELECT INTO query. Here's what I tried:
Original query that selects top 5 most populated academic section (i.e. those that have most staff)
SELECT TOP 5 Staff.WorksIn AS [Section], COUNT(*) AS [Staff Count]
FROM Staff, AcademicSection
WHERE (((AcademicSection.[ASId])=[WorksIn]))
GROUP BY Staff.WorksIn
ORDER BY Count(*) DESC;
Now I need to get and add in AcademicSection.LongName into it, replacing [Section] or using it to acquire corresponding LongName. How would I do that, please? I tried this:
SELECT LongName FROM AcademicSection INNER JOIN (SELECT TOP 5 Staff.WorksIn AS [Section], COUNT(*) AS [Staff Count]
FROM Staff, AcademicSection
WHERE (((AcademicSection.[ASId])=[WorksIn]))
GROUP BY Staff.WorksIn
ORDER BY Count(*) DESC) ON AcademicSection.[ASId] = [Section];
But it doesn't work saying that JOIN expression is not supported.
|