?
Solved

using two ANDs in a Query

Posted on 2011-09-29
15
Medium Priority
?
270 Views
Last Modified: 2012-05-12
Hi all,

I would like to specify multiple query using two ANDs using Select Query. I am basing a report which has to pick two ranges within the same field, ie.

range from 60 to 69 and from 90 to 99.

I have tried the following in the criteria box.

(between 60 AND 69) and (between 90 AND 99)....no luck

I have tried permutations of the above but to no avail.

Grateful to know if it can be done?

Thanks
0
Comment
Question by:PipMic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 3
  • +1
15 Comments
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 36813675
It not AND but OR to use.

/gustav
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 36813676
I am assuming that the field value that has to be in the range cannot be in 60 to 69 and 90 to 99 as it would be a discrete value - either 60 to 69 or 90 to 99, so the where clause would be BETWEEN 60 an 69 or BEWTWEEN 60 and 99

Kelvin

0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 36813679
That is something like WHERE ID Between 60 and 69 or ID between 90 and 99

Kelvin
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:PipMic
ID: 36813696
Hi guys,

I would like my query to pick "both ranges", ie, the values pertaining to ID from 60 to 69 "and" the values pertaining to the range 90 to 99.
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 36813706
Can you give an example of the sort of data you are talking about?
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 232 total points
ID: 36813741
> I would like my query to pick "both ranges" ..

That's what have been written:

(between 60 AND 69) OR (between 90 AND 99)....

/gustav
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 36813756
Another way, but a bit heavy going would be where ID IN(60,61,62,63,64,65,66,67,68,69,90,91,92,93,94,95,96,97,98,99)
0
 
LVL 5

Assisted Solution

by:DerZauberer
DerZauberer earned 176 total points
ID: 36813771
SELECT field1, field2, ... FROM table WHERE (field BETWEEN 60 AND 69) OR (field BETWEEN 90 AND 99)

Open in new window

0
 

Author Comment

by:PipMic
ID: 36813801
Hi,

I have a field ID as autonumber.

But I would like to select two ranges from the same field eg. Simply put...

1 - A
2 - A
3 - B
4 - C
5 - C

Therefore I would like to select the values pertaining to two ranges i.e. from 1 to 2 and from 4 to 5.

Thanks

0
 
LVL 22

Assisted Solution

by:Kelvin Sparks
Kelvin Sparks earned 92 total points
ID: 36813826
SELECT Other field from thetable
WHERE ID BETWEEN 1 and 2 or ID Between 4 and 5
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 36813831
Will return
A
A
C
C
0
 
LVL 51

Assisted Solution

by:Gustav Brock
Gustav Brock earned 232 total points
ID: 36813834
That would be:

(between 1 AND 2) OR (between 4 AND 5)

/gustav

0
 
LVL 5

Assisted Solution

by:DerZauberer
DerZauberer earned 176 total points
ID: 36813845
In your example your filter MUST be like this:

Filter: (ID between 1 and 2) OR (ID between 4 and 5)

If you use "AND" it has to meet both criterias at same time, which can never be true!
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 36813853
I have successfully used these expressions without bracketing for the last 15 years1 The query wizards add them, and unless you need toem to determine a order of operations they can be left off - and often result in increased performance.

But this is only detracting from the question.
0
 

Author Closing Comment

by:PipMic
ID: 36813921
worked well
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question