sql, And, Or Problems

# Thread: sql, And, Or Problems

1. Senior Member
Join Date
Dec 1969
Posts
590

## sql, And, Or Problems

I want to retrieve a recordset where the field &#039F1&#039 is Yes or Maybe and field &#039F2&#039 is Yes or Maybe:<BR>I tried this:<BR><BR>sql = SELECT * From Table WHERE F1 = &#039Yes&#039 OR &#039Maybe&#039 AND F2 = &#039Yes&#039 OR F2 = &#039Maybe&#039<BR><BR>However the recordset I get Includes records which have F2 = No.<BR><BR>What Am I doing wrong?<BR><BR>Please help me..<BR><BR>Nick

2. Senior Member
Join Date
Dec 1969
Posts
2,849

## RE: sql, And, Or Problems

Ah, boolean logic. Tell me if this statement is true or not:<BR><BR>I want to go to the store or go to the carnival and I want to meet a friend there.<BR><BR>Now, if I go to the store and don&#039t meet a friend there, is this statement true? Maybe. What if I go to the store and don&#039t meet a friend, is this statement true? Maybe. It depends on the order of operations for the AND and OR logical operators. <BR><BR>Do I mean:<BR><BR>I want to (go to the store or go to the carnival) and I want to meet a friend there.<BR><BR>or do I mean:<BR><BR>I want to go to the store or (go to the carnival and I want to meet a friend there).<BR><BR>Note that the parenthesis make a big difference on the truth table for this statement. So, you just need to parenthesize your statement:<BR><BR>SELECT * From Table WHERE (F1 = &#039Yes&#039 OR F1 = &#039Maybe&#039) AND (F2 = &#039Yes&#039 OR F2 = &#039Maybe&#039)<BR><BR>Happy Programming!<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•