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开发者_如何转开发
select * from mytable where 25 between col1 and col2;
You can try:
If you want to include col1 and col2 in the search:
select * from table where YOUR_NUM >= col1 and YOUR_NUM <= col2;
If not:
select * from table where YOUR_NUM > col1 and YOUR_NUM < col2;
精彩评论