Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

using two ANDs in a Query

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
PipMic
Asked:
PipMic
  • 7
  • 3
  • 3
  • +1
5 Solutions
 
Gustav BrockCIOCommented:
It not AND but OR to use.

/gustav
0
 
Kelvin SparksCommented:
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
 
Kelvin SparksCommented:
That is something like WHERE ID Between 60 and 69 or ID between 90 and 99

Kelvin
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
PipMicAuthor Commented:
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
 
Kelvin SparksCommented:
Can you give an example of the sort of data you are talking about?
0
 
Gustav BrockCIOCommented:
> 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
 
Kelvin SparksCommented:
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
 
DerZaubererCommented:
SELECT field1, field2, ... FROM table WHERE (field BETWEEN 60 AND 69) OR (field BETWEEN 90 AND 99)

Open in new window

0
 
PipMicAuthor Commented:
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
 
Kelvin SparksCommented:
SELECT Other field from thetable
WHERE ID BETWEEN 1 and 2 or ID Between 4 and 5
0
 
Kelvin SparksCommented:
Will return
A
A
C
C
0
 
Gustav BrockCIOCommented:
That would be:

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

/gustav

0
 
DerZaubererCommented:
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
 
Kelvin SparksCommented:
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
 
PipMicAuthor Commented:
worked well
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 7
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now