1

I have a function which accepts an integer then checks it against a MYSQL table to check if the number falls between the ranges of a a records defined in the table.

The only thing is, my date ranges are defined in a single column as a string in the following format:

0-25

When making a query against this, is there any way I can parse the value in the cell to create a 'minvalue' and 'maxvalue' range?

So far I have:

"SELECT * FROM high_performing_instructors_reference WHERE score BETWEEN....." 

I can edit the tables to add min and max values and use PHP explode but I wanted to see if there was a way of doing this in MYSQL first. Thanks

1
  • 2
    Normalize. Your. Data. That's it. No other way to do this properly. Commented Aug 5, 2014 at 8:39

1 Answer 1

3

Use SUBSTRING_INDEX to get the parts of the range column.

WHERE score BETWEEN SUBSTRING_INDEX(rangecol, '-', 1) AND SUBSTRING_INDEX(rangecol, '-', -1)
Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot man....u have saved my lots of time and my long code shorten to some lines...
Yes, just one word: Brilliant! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.