Abishek Arumugam
Abishek Arumugam

Reputation: 35

Select many intervals from a single table based on column value

My intend is to select many intervals based on column value at the same time..Is it possible enter image description here

This is my sample data, it consists of 1024 rows ,i want to select multiple intervals based on wavelength column ex:(341-348) (551-664) (998-1021) from a single table

Upvotes: 1

Views: 1061

Answers (2)

valex
valex

Reputation: 24134

You should use BETWEEN and OR to get records:

SELECT * FROM TABLE1 
   WHERE wavelenght BETWEEN 341 AND 348 
         OR wavelenght BETWEEN 551 AND 664  
         OR wavelenght BETWEEN 998 AND 1021  

Upvotes: 1

Smutje
Smutje

Reputation: 18123

To query not for a specific value, but for a range of values, SQL invented the BETWEEN operator for the WHERE clause (http://www.w3schools.com/sql/sql_between.asp), e.g.

SELECT columns
FROM yourtable
WHERE wavelength BETWEEN lowerbound AND upperbound;

Upvotes: 0

Related Questions