Hi Mihaela, this has to do with Boolean logic. If you need an introduction, this seems like a pretty good video on it: Boolean algebra #1: Basic laws and rules - YouTube
Basically, AND and OR are logical keywords that combine multiple TRUE/FALSE statements.
When you use AND between two statements, it means that both statements must be true for the whole thing to be true. For instance, if you only like animals that have two legs AND have wings, you like birds but not kangaroos.
When you use OR between two statements, it means that either must be true for the whole thing to be true. If you only like animals that have two legs OR have wings, you like both birds and kangaroos.
The parentheses have to do with grouping and order of operations. When you put parentheses around part of the expression, it makes that part inside the parentheses into its own mini-expression.
For instance, let's say that your Boolean expression is that you like animals that:
(Have Four Legs AND Have Antlers) OR Have Wings
In this situation, the part in the parentheses has to be evaluated before the rest. For instance, antelope would be TRUE for that expression, so you like antelope. Also, birds are TRUE because they have wings (in the main expression). However, you would not like dogs, because they do not have both four legs AND antlers (nor do they have wings).
Try and think of it in terms of logical truth. AND requires multiple statements to be TRUE, while OR requires one of the conditions to be TRUE.
1=1 is always True
2=2 is always True
0=1 is always False
AND Example 1:
if 1=1 and 0=1 then 'A' else 'B' end
The statement above would return B, since 0=1 is false. The AND condition requires both conditions to be true.
AND Example 2:
if 1=1 and 2=2 then 'A' else 'B' end
The statement above would return A, since 1=1 is True and 2=2 is True. Both conditions are true.
OR Example 1:
if 1=1 or 0=1 then 'A' else 'B' end
The statement above would return A, since one of the conditions is True.OR simply requires one of the conditions to be True.
Adding Parenthesis: Parenthesis simply require the logic to check the entire statement within the parenthesis
if (1=1 and 2=2 OR 0=1) then 'A' else B end
The statement above would return A since 1=1 AND 2=2. The 0=1 returns False, but since 1=1 and 2=2 is True it will still return A. The condition on the left side met the requirement of True.
I hope this answers your question.
1 of 1 people found this helpful
Thank you very much David!
that means if I I want to SELECT all patients from AB, ON, BC and so on, but not from Europe or other country, I use an OR? meaning give me any of these records
I need all patients who are Canadian residents but no other countries.
Please and thank you very much,
Yes, you would use OR to link expressions that compare the patient province field to all the Canadian provinces. If you have a country field, that would be even easier, as you wouldn't need any custom Boolean logic.
Thank you very much, I really appreciate
This is correct too if you use an if statement, Thank you very much