What we say is often not logical... from a mathematical or computer's point of view. Let's say we want a list of all donors living in New York and Chicago. We would probably write the following:
Select individuals where city = "New York" and city = "Chicago"
Sorry, that's wrong. The computer will take each individual, one at a time, and perform the test. With an "and", both conditions must be true in order for the individual to be selected. Obviously, the individual's address cannot have both New York and Chicago in the same record. So, we will get no data. Although, in English, we typically say "New York" and "Chicago", in computer-speak we should say "New York" or "Chicago". With an "or", either or both have to be true for the individual to be selected. So, we should have written "or" instead of "and."
We also need to be careful when mixing "and" and "or." For example, if we were to write the following:
Select individuals where city = "New York" or city = "Chicago"
and gift > $1000
we may have a problem. The "and" is always paired before the "or." In other words, we have actually written the following:
Select individuals where city = "New York"
or (city = "Chicago" and gift > $1000)
We will actually end up with everyone from New York plus only those individuals in Chicago that gave over $1000. This can be a bit hard to remember so it's always a great idea to put the brackets in so we don't need to remember and neither will other people. So, the above should have been written as follows:
Select individuals where (city = "New York" or city = "Chicago")
and gift > $1000
This will select all individuals in New York and Chicago (careful with my English) that have also given over $1000.
|