Its difficult to know just what the original developer had in mind with this
criterion. AND and OR are Boolean logical operators. AND means both
conditions must be True for the expression as a whole to be True, OR means
either one can be True for the expression as a whole to be True.
As written the expression <> 5 or 7, if in the criteria row of a column
MyField in a query in design view, would be the same as the following
statement:
WHERE MyField <> 5 OR MyField = 7
This question would be asked of every row and if True the row is returned.
The first part will be True for any row where MyField does not equal 5, i.e.
every row apart from those where MyField = 5. The second part will be True
for those rows where MyField equals 7. But as an OR operator is used here
any row where MyField = 7 will already be returned because it doesn't equal
5, so the first part of the expression is already True. As an OR operation
requires only one part to be True then the second part of the expression is
doing nothing.
If the developer meant that only rows where MyField was equal to neither 5
or 7, i.e. all rows bar those with one of those values in MyField then
another Boolean operator can be brought into p[lay, the NOT operator, which
as you'd expect negatives the expression so it would be:
WHERE NOT(Myfield= 5 OR MyField = 7)
in query d4sign vie this can be entered in the criteria row of MyField as:
Not(5 Or 7)
As rule of thumb think of OR operations being used on one column; to return
rows with either value. Think of AND operations being used on combinations
of columns; to return rows with a value in each, e.g. all employees in London
with salaries greater than 30,000 GBP:
WHERE City = "London" AND Salary > 30000
In query design view you'd do this by putting "London" in the first criteria
row of the City column and > 30000 in the criteria row of the Salary column.
To return all employees in London or Manchester regardless of salary would be:
WHERE City = "London" OR City = "Manchester"
In query design row you'd put each city name on separate criteria rows of
the city column. Note that in everyday English we might well say "all
employees in London and Manchester" when meaning the above. Boolean logic
however requires an OR.
If we wanted to combine the two the expression would be:
WHERE (City = "London" OR City = "Manchester") AND Salary > 30000
Note that the OR operation is included in parentheses here to force it to
evaluate independently of the AND operation. In query design view the city
names would again be entered on separate criteria rows of the city column,
but in this case >30000 would have to be entered twice, on two separate
criteria rows of the Salary column, each alongside one of the criteria on the
City column.
Ken Sheridan
Stafford, England