Sql "ranges" and wildcards

Fill in the sql noob here.

Trying to think of a way to store some data in a table that looks something like this:

"0-15", "low", "1-3"

"45-50", "med", "*"

"*", "*", "1000"

where columns 1 and 3 are ranges of integers and col 2 is an enumerated type (can be stored as anything really).

I want to be able to put wildcards in the table to keep the number of rows down while still not "missing" anything.

from what I understand, columns 1 and 3 are best stored as two columns of integers, with -INT_MAX being INT_MAX or whatever as a "wildcard". (select bla from bla where col1.1> val and col1.2 <val)

is this a smart strategy?

Column

seems harder, choose bla from bla where col2 = 'med' or col2 = '*' doesn't seem right. i could probably do it numerically exactly like 1 and 3, but rather not

anyone want to enlighten me?

+2


source to share


2 answers


My advantage would be to use it NULL

as a wildcard, as it will stand out in a noticeable way to anyone looking at the database. In this case, each element of your sentences WHERE

will look something like this:

WHERE (77777 > min_value OR min_value IS NULL)
  AND (77777 < max_value OR max_value IS NULL)
  AND (col2 = 'med' OR col2 IS NULL)

      



This is the same basic idea *

you had earlier, but using a value that SQL recognizes as different from normal values.

+3


source


The natural thing to do, given SQL, would be to use a NULL

substitution as your value.



+1


source







All Articles