S
S
sokira2020-05-08 13:06:44
MySQL
sokira, 2020-05-08 13:06:44

How to store in mysql an interval "from N to infinity"?

There is a need to save several intervals in the database.
The structure is simple. Let's take two columns: "from" and "to". Integers.

When an interval has values ​​on both sides, then everything is simple and clear.
for example

  • 0 to 99
  • from 100 to 199

If we take an open interval
  • from 200 to [no limit]
  • N to [no limit]

What value should be stored in the database to indicate the infinite right border, so that the selections work correctly later?

Find an entry where "Up to >= 10,000"

Entering just a large value that definitely won't be requested? For example, "9999999"
Or is there some other solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2020-05-08
@sokira

In databases, the absence of a value is denoted as NULL.

WHERE ( Val >= ValFrom ) AND (( Val <= ValTo ) OR ( ValTo IS NULL ))

X
xmoonlight, 2020-05-08
@xmoonlight

0 - fit! :))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question