A null is not equal to another null, but is not DISTINCT from another null
either (equality and DISTINCT are two different concepts, in SQL): that
means that unless there is a bug, for a GROUP made of a single field,
multiple records with a null will make only one group, not one group for
each of the multiple null. Also, if there is a matching USER, the left
join won't generate a NULL for any field associated to table1. This leaves
the case where table1 has INITIALLY a null value for one of its field (not
involved in the join), in particular, for Task_type, which can, in this
case, lead to possible ambiguity, indeed.
users.name=Joe Blow, table1.task_id = null
can thus mean that Joe, in table Users, is NOT in table1, or that he is
in table1, but associated to as null task_id.
If you insert
table1.Assigned_to
in the GROUP By clause, the field we join ON:
ON USERS.USER = table1.ASSIGNED_TO
then you can REMOVE THE AMBIGUITY :
users.Name = Joe Blow, table1.Assigned_to = null, table1.task_id =
null
is a record without match in table1
users.Name = Joe Blow, table1.Assigned_to = Joe Blow,
table1.task_id = null
is a record with an initial null for task_id.
Vanderghast, Access MVP
Dale Fye said:
Michael,
Won't adding the Task_Type to the Group By clause result in
(potentially)
multiple rows for each PM/User, and no way to distinquish which
Task_Type the
count applies to (since the SELECT clause does not contain a Task_Type
field?
--
Dale
email address is invalid
Please reply to newsgroup only.
:
SELECT USERS.PM,
USERS.USER,
USERS.NAME,
Count(table1.TASK_ID) AS CountOfTASK_ID
FROM USERS LEFT JOIN table1 ON USERS.USER = table1.ASSIGNED_TO
WHERE (((USERS.PM)=[Enter Supervisor])
AND ((table1.TASK_TYPE)="PICKING"
Or (table1.TASK_TYPE)="REPLENISH")
OR table1.Task_Type IS NULL)
AND (((table1.TASK_STATUS)="AVL"
Or (table1.TASK_STATUS)="ASN")
OR Table1.Task_Status IS NULL)
GROUP BY USERS.PM, USERS.USER, USERS.NAME, table1.TASK_TYPE
Note that the sub-query in the FROM clause (a virtual table) is also a
valid
approach too.
Vanderghast, Access MVP
So if I understand you correctly, I am to add " Or Is Null" to the
criteria
for task_status and task_type and change the totaling for task type
tp a
"WHERE" function.
I tried this however the query has been running for >5 minutes and
still
has
not returned a result.
:
As mentioned by Dale, your WHERE clause (and your HAVING clause)
undo the
job made by the outer join. Indeed, after the join is made, values
under
table1.status can be null (due to the outer join) so, at least, you
should
also consider to add : OR table1.Task_Status IS NULL in the WHERE
clause
and OR table1.Task_Type IS NULL in the HAVING clause. Note
also
that
your HAVING clause criteria could be moved into your WHERE clause
(and
doing
so, may make the execution time shorter)..
Vanderghast, Access MVP
Let me show you the SQL as I have already tried to change the join
type.
--------------
SELECT USERS.PM, USERS.USER, USERS.NAME, Count(table1.TASK_ID) AS
CountOfTASK_ID
FROM USERS LEFT JOIN table1 ON USERS.USER = table1.ASSIGNED_TO
WHERE (((table1.TASK_STATUS)="AVL" Or (table1.TASK_STATUS)="ASN"))
GROUP BY USERS.PM, USERS.USER, USERS.NAME, table1.TASK_TYPE
HAVING (((USERS.PM)=[Enter Supervisor]) AND
((table1.TASK_TYPE)="PICKING"
Or
(table1.TASK_TYPE)="REPLENISH"));