Lets say that I have a table A. This table has ID, X_value, Y_value. Here is content of table A:
Table A
ID X_value Y_value
1 100 150
2 110 170
3 120 190
Now, if I’m comparing number 130 with range numbers(X_value – Y_value) I would like to get ID of range with smallest(minimal) difference! If I can name it that way? Right away we see that number 130 will fall into all this ranges, but I need ID of range with smallest(minimal) difference between 130 and numbers of range. To elaborate that difference:
For range 1: 130-100=30 and 150-130=20
For range 2: 130-110=20 and 170-130=40
For range 3: 130-120=10 and 190-130=60
From this elaboration we see that minimal difference is at third range(that is 10) so I would like to get ID 3. What will be a query for this example if I have this table within MySQL db?!
or