Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL : select values between multiple ranges

Tags:

sql

mysql

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
like image 615
user2186465 Avatar asked Dec 24 '22 21:12

user2186465


1 Answers

select id, price
from tablename
where price between 500 and 1500
   or price between 2500 and 4500
like image 71
jarlh Avatar answered Dec 27 '22 19:12

jarlh