mike mike - 2 months ago 6
MySQL Question

How to search between columns in mysql

i have two columns that store values(numbers), how do i select where my given number is between the values in the two columns?

Example

`id | col1 | col2`
`1 | 20 | 50`
`2 | 200 | 400`
`3 | 500 | 650`


If I have a value of 25, how can i select records where the value of 25 is between them which in this case would be row 1

Answer
select * from mytable where 25 between col1 and col2;