Re: Find between a list of values

From: Jerry Stuckle <jstucklex_at_attglobal.net>
Date: Sat, 31 Mar 2018 08:40:32 -0400
Message-ID: <p9nvjb$s8$1_at_jstuckle.eternal-september.org>


On 3/31/2018 4:42 AM, gandalf.corvotempesta_at_gmail.com wrote:
> Let's assume something like this:
>
> start1,stop1|start2,stop2|start3,stop3
>
> I would like to select all rows having a defined value (in example "1325" between one of the each group, in other words:
>
> WHERE
> (
> ( 1325 BETWEEN start1 AND stop1 )
> OR ( 1325 BETWEEN start2 AND stop2 )
> OR ( 1325 BETWEEN start3 AND stop2 )
> )
>
>
> Is this possible, with a single query using indexes ? It should be pretty fast.
>
> I don't know how many "groups" are stored in the field. It could be 1:
>
> start1,stop1
>
> 2:
>
> start1,stop1|start2,stop2
>
> or more....
>

The first thing you need to do is normalize your database. One value per row/column. If I read this properly, you should have a second table linked to the first with three columns - id of the first table row, start and stop. You may add a fourth column for a unique id of the row.

Although I hate recommending Wikipedia, their article on database normalization is quite good.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex_at_attglobal.net
==================
Received on Sat Mar 31 2018 - 14:40:32 CEST

Original text of this message