MySql search integer range from number with dash

Viewed 1664

I have table in that I have one field with dash value. Like...

enter image description here

I need to search this with between condition.

For example if I have one value 25 then I need to search the records which include the value 25 like 20-31. In above image there are 6 records which include 25 value. So it should return 6 records.

Please help me in this query ? What would be the query for that ?

5 Answers

If you want to get values beween 35 and 39, you can use below query,

SELECT 
    *
FROM
    yourtable
WHERE
    35 && 39 
    BETWEEN SUBSTRING_INDEX(tablecolumn, '-', 1) + 0 AND 
SUBSTRING_INDEX(tablecolumn, '-', - 1) + 0
Related