After staring at it for an hour, I finally solved this problem, but I wanted to see if anyone could tell me why it was happening. I have a query with tyhe following (abreviated) SQL:
Now, in this query ObjectTotals is a query and FMS_OBJECT_CODE is a table. The SQL for ObjectTotals is:
Seems simple enough to me. The problem was, my first query didn't return any rows. I ran ObjectTotals on its own and compared it to FMS_OBJECT_DESC, and there were many records that matched on the join column. According to everything I know about SQL, this means that there's no way the original query could return nothing.
Well, after playing with it for a while, I discovered that if I changed the GROUP BY clause in ObjectTotals to
then everything worked perfectly.
My question is: WHY?!?!? Am I missing some subtle semantic quirk of SQL, or is the Access 97 SQL interpreter just a peice of junk? I mean, if I take the original SQL for ObjectTotals and add
at the end, it will return the exact same rows in the exact same order as if I change the GROUP BY clause, but still doesn't work in my original query. I thought that as long as they returned the same rows, it didn't matter what the underlying SQL was. Apparently I was wrong, but can someone please explain why?
Code:
SELECT ...
FROM ObjectTotals INNER JOIN FMS_CODE_DESC ON ObjectTotals.object = FMS_CODE_DESC.FMS_OBJ;
Code:
SELECT object, [snow code], sum(amount) AS totamt
FROM fms_tran
WHERE [r/b code]=0
GROUP BY [snow code], object;
Well, after playing with it for a while, I discovered that if I changed the GROUP BY clause in ObjectTotals to
Code:
GROUP BY object, [snow code]
My question is: WHY?!?!? Am I missing some subtle semantic quirk of SQL, or is the Access 97 SQL interpreter just a peice of junk? I mean, if I take the original SQL for ObjectTotals and add
Code:
ORDER BY object