Update at the bottom.
I am trying to do a self outer join that, for each record, returns it and all other records occuring later than it, or NULL if it itself is the latest record. This is my sql code:
SELECT A.[CR#], A.REGIS_STATUSDATE, B.REGIS_STATUSDATE
FROM CR_ADMIN_REGIS_STATUS A LEFT OUTER JOIN CR_ADMIN_REGIS_STATUS B
ON A.[CR#]=B.[CR#] AND A.REGIS_STATUSDATE < B.REGIS_STATUSDATE
My issue is this is that when, for a given [CR#], A.REGIS_STATUSDATE is a maximum (and therefore the B.REGIS_STATUSDATE cannot be greater than it), that row is not included in my result.
For example, if CR_ADMIN_REGIS_STATUS looks like this:
CR# REGIS_STATUSDATE
1 5/1/12
1 5/2/12
1 5/3/12
2 5/1/12
2 5/2/12
I expect the result of my query to be
CR# A.REGIS_STATUSDATE B.REGIS_STATUSDATE
1 5/1/12 5/2/12
1 5/1/12 5/3/12
1 5/2/12 5/3/12
1 5/3/12 NULL
2 5/1/12 5/2/12
2 5/2/12 NULL
Instead I get this:
CR# A.REGIS_STATUSDATE B.REGIS_STATUSDATE
1 5/1/12 5/2/12
1 5/1/12 5/3/12
1 5/2/12 5/3/12
2 5/1/12 5/2/12
Given that my query is a LEFT OUTER JOIN, and I have no WHERE clause, I expect all rows from my original table to be in the result, but this is not the case. What am I missing here?
Edit: This is in Access 2007
Update: I decided to see what would happen if I copied sections of the table CR_ADMIN_REGIS_STATUS into a separate table and ran my query against that. Even when I had just straight up copied the entire table into the new one (manually) the query worked! This was only the case when actually copying and pasting though, when I would SELECT * INTO another table the problem would persist.
Eventually I discovered that if I ran the query against
SELECT *
FROM CR_ADMIN_REGIS_STATUS
UNION ALL SELECT TOP 1 *
FROM CR_ADMIN_REGIS_STATUS;
rather than CR_ADMIN_REGIS_STATUS itself my query returned the desired result. Weird. I also had a similar query against a similar table which worked from the start, so it seems this was an issue limited to this one table.