Home > Net >  Selecting a row where range lies between two columns in mysql
Selecting a row where range lies between two columns in mysql

Time:07-06

I have 4 columns in my table

id , amount_from, amount_to, amount

My value is lets suppose 350000

The data in the table is:

image of table data

i want to query which column have a amount_from greater then 350000 and amount_to less then 350000

select * from table where id = 5 and amount_from >= 355000 and amount_to <= 355000

but i am getting 0 results.

CodePudding user response:

Normally you would use the keyword 'BETWEEN'

SELECT * FROM table WHERE id=5 AND 350000 BETWEEN amount_from AND amount_to
  • Related