AND
is a logical operator. &
is a concatenation operator. Review Table of operators for more details about the various operators available in Access 2007.
To see the differences in action, start with this as table WeinerDog
.
id field1 field2
1 a
2 y
3
The blanks in the field1
and field2
columns represent Null values.
Next run this query:
SELECT
WeinerDog.id,
WeinerDog.field1,
WeinerDog.field2,
(WeinerDog.field1 Is Null)
& (WeinerDog.field2 Is Null) AS concat_result
FROM WeinerDog
WHERE
(WeinerDog.field1 Is Null) & (WeinerDog.field2 Is Null);
That query should give you this result set:
id field1 field2 concat_result
1 a 0-1
2 y -10
3 -1-1
Examine the concat_result
column. It contains strings which are the truth values of the 2 expressions concatenated together. Those truth values are either True (-1) or False (0). However, since the result of concatenation must be a string, the numeric truth values are first cast as strings before they are joined together.
Then examine the WHERE
clause. The db engine will give you all rows for which the WHERE
clause evaluates as True
. And actually, not just -1, but any non-Null value other than zero can stand in for True
. As you can see from the concat_result
column, none of those rows will be evaluated as zero (False
) by the WHERE
clause ... so all rows in the table will be included in the query result set.
If you change the WHERE
clause to substitute AND
for &
, the query will return only the WeinerDog
row (id=3) which has Null for both field1
and field2
.
WHERE
(WeinerDog.field1 Is Null) AND (WeinerDog.field2 Is Null);