A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"And" "Or" Search Criteria



 
 
Thread Tools Display Modes
  #1  
Old June 8th, 2007, 12:08 AM posted to microsoft.public.access.queries
[email protected]
external usenet poster
 
Posts: 1
Default "And" "Or" Search Criteria

I have a field that contains summaries of articles. I want to search
within the field for the following:
"Red" and "Blue" or "Green" and Blue"
I want my results to return all articles that contain both "red" and
"blue" in an article and all articles that contain both "green" and
"blue" in an article. I can easily return all articles that contain
"red" or "green" but the "AND" function is causing me to return ZERO
articles which I know is incorrect.
Thanks for all of your help in advance.

  #2  
Old June 8th, 2007, 01:42 AM posted to microsoft.public.access.queries
Ken Sheridan
external usenet poster
 
Posts: 3,433
Default "And" "Or" Search Criteria

In your example all the articles to be returned will contain 'blue' and will
also contain either 'red' or 'green' (or possibly both 'red' and 'green'),
So, assuming you are using the LIKE operator to match the patterns the logic
is:

WHERE summary LIKE "*blue*" AND (Summary LIKE "*red*" OR summary LIKE
"*green*)

By enclosing the Boolean OR operation in parentheses this evaluates
independently, so if the parenthesised expression evaluates to TRUE (the
article contains 'red' or 'green') AND the article also contains 'blue' the
complete expression will evaluate to TRUE and the row will be returned.

The expression above is the same logically as:

WHERE (summary LIKE "*blue*" AND Summary LIKE "*red*") OR (summary LIKE
"*blue*" AND summary LIKE "*green*)

which is closer to your plain English expression – "Red" and "Blue" or
"Green" and Blue"; the difference is the use of the parentheses in the formal
logical expression, which are omitted in the plain English equivalent.

Ken Sheridan
Stafford, England

" wrote:

I have a field that contains summaries of articles. I want to search
within the field for the following:
"Red" and "Blue" or "Green" and Blue"
I want my results to return all articles that contain both "red" and
"blue" in an article and all articles that contain both "green" and
"blue" in an article. I can easily return all articles that contain
"red" or "green" but the "AND" function is causing me to return ZERO
articles which I know is incorrect.
Thanks for all of your help in advance.



  #3  
Old June 8th, 2007, 02:59 AM posted to microsoft.public.access.queries
Chris2
external usenet poster
 
Posts: 271
Default "And" "Or" Search Criteria


wrote in message
oups.com...
I have a field that contains summaries of articles. I want to

search
within the field for the following:
"Red" and "Blue" or "Green" and Blue"
I want my results to return all articles that contain both "red" and
"blue" in an article and all articles that contain both "green" and
"blue" in an article. I can easily return all articles that contain
"red" or "green" but the "AND" function is causing me to return ZERO
articles which I know is incorrect.
Thanks for all of your help in advance.


tpmcanally,

SELECT your columns
FROM your table AS YT1
WHERE (YT1.ArticleSummary LIKE "*Red*"
AND YT1.ArticleSummary LIKE "*Blue*")
OR (YT1.ArticleSummary LIKE "*Green*"
AND YT1.ArticleSummary LIKE "*Blue*")

(That's aircode, but the logic should be right crosses fingers.)


Sincerely,

Chris O.



  #4  
Old June 8th, 2007, 10:24 AM posted to microsoft.public.access.queries
Ken Sheridan
external usenet poster
 
Posts: 3,433
Default "And" "Or" Search Criteria

Oops, missed a quotes character:

WHERE summary LIKE "*blue*" AND (summary LIKE "*red*" OR summary LIKE
"*green*")

Ken Sheridan
Stafford, England

" wrote:

I have a field that contains summaries of articles. I want to search
within the field for the following:
"Red" and "Blue" or "Green" and Blue"
I want my results to return all articles that contain both "red" and
"blue" in an article and all articles that contain both "green" and
"blue" in an article. I can easily return all articles that contain
"red" or "green" but the "AND" function is causing me to return ZERO
articles which I know is incorrect.
Thanks for all of your help in advance.


  #5  
Old June 8th, 2007, 09:16 PM posted to microsoft.public.access.queries
[email protected]
external usenet poster
 
Posts: 1
Default "And" "Or" Search Criteria

On Jun 8, 4:24 am, Ken Sheridan
wrote:
Oops, missed a quotes character:

WHERE summary LIKE "*blue*" AND (summary LIKE "*red*" OR summary LIKE
"*green*")

Ken Sheridan
Stafford, England



" wrote:
I have a field that contains summaries of articles. I want to search
within the field for the following:
"Red" and "Blue" or "Green" and Blue"
I want my results to return all articles that contain both "red" and
"blue" in an article and all articles that contain both "green" and
"blue" in an article. I can easily return all articles that contain
"red" or "green" but the "AND" function is causing me to return ZERO
articles which I know is incorrect.
Thanks for all of your help in advance.- Hide quoted text -


- Show quoted text -


Thanks everyone. Adding the word 'Like' and the "*xxxxx*" worked
perfectly.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:29 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.