HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Select a range of integers

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
selectintegersrange

Problem

I have a 'range' of integers (in this case destination ports) that occur:

For example: 33848-33254.

I want to select 'all' of these without having to do one at a time. is there a range operator? Or should I just use 'between'?

Solution

You can use BETWEEN or greater than/less than operators:

select *
from yourtable
where col1 >= 33254 and col1 <= 33848;


or

select *
from yourtable
where col1 between 33254 and 33848;


see SQL Fiddle with Demo

Code Snippets

select *
from yourtable
where col1 >= 33254 and col1 <= 33848;
select *
from yourtable
where col1 between 33254 and 33848;

Context

StackExchange Database Administrators Q#24982, answer score: 7

Revisions (0)

No revisions yet.