TastyWheat
Registered User.
- Local time
- Today, 08:44
- Joined
- Dec 14, 2005
- Messages
- 125
I have a query worked out with the exact result I'm looking for, but it's kind of slow. Can someone find another way to write up this query?
The inner (green) query pairs every employee with every class they could possibly take (cross product). Then that query is joined with the attendance table to show who has taken which class. If a class hasn't been taken the ClassID will be null like so:
So is there an easier way to get this result?
Code:
SELECT EID, ShortName, ClassID
FROM (
[COLOR="SeaGreen"] SELECT Employee.EID, Class.CID, Class.ShortName
FROM Employee, Class[/COLOR]
) AS Temp1
LEFT JOIN [Class Attendance]
ON (Temp1.CID=[Class Attendance].ClassID) AND
(Temp1.EID=[Class Attendance].EmployeeID);
Code:
EID ClassID ShortName
=========================
111-11-1111 1 ISM
111-11-1111 2 ABC
111-11-1111 BGP
222-22-2222 ISM
222-22-2222 2 ABC
222-22-2222 3 BGP