6

I have a table like the one below...

ID    Price
==== ======
1    1000
2    2000
3    4000
4    5000

Now I need a query to select values between 500 and 1500 And between 2500 and 4500. i.e. like using two between in a single select query...

is it possible?

output should be:

ID    Price
==== ======
1    1000
3    4000

1 Answer 1

11
select id, price
from tablename
where price between 500 and 1500
   or price between 2500 and 4500
Sign up to request clarification or add additional context in comments.

2 Comments

What if the ranges are coming from a table? So it is possible to have dynamic query for multiple ranges?
@Aryo, you can probably do a JOIN and put the conditions in the ON clause. Ask a question and put the link here, and I'll take a look at it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.