TastyWheat
Registered User.
- Local time
- Today, 10:10
- Joined
- Dec 14, 2005
- Messages
- 125
I've done double and even triple joins before, but this isn't working for me, probably because I'm using a SELECT statement instead of a table. Here's the basic (working) query:
Now that works perfectly fine, but the problem is I only want the employee to join with the most recent position and store change. So I tried something like this:
It tells me "Syntax error in JOIN operation" and it highlights the first occurence of "[Position Change]" (the part in bold). Using the 1st query I don't see how I can filter out the correct records.
Code:
SELECT Employee.*, NewPositionID AS [Position], NewStoreID AS [Store]
FROM Employee
LEFT JOIN (
[Position Change] INNER JOIN [Store Change]
ON [Position Change].EmployeeID=[Store Change].EmployeeID
) ON Employee.EID=[Position Change].EmployeeID;
Code:
SELECT Employee.*, NewPositionID AS [Position], NewStoreID AS [Store]
FROM Employee
LEFT JOIN (
(SELECT TOP 1 * FROM [B][Position Change][/B] ORDER BY EffectiveDate Desc)
INNER JOIN (SELECT TOP 1 * FROM [Store Change] ORDER BY EffectiveDate Desc)
ON [Position Change].EmployeeID=[Store Change].EmployeeID
) ON Employee.EID=[Position Change].EmployeeID;