Monday, 4 March 2013

Get a row which has range of given number


Table Name shipment_charge
+----+------+------+------+
| id | price | min | max |
+----+------+------+------+
| 1 | 100 | 10 | 20 |
| 2 | 200 | 21 | 30 |
| 3 | 300 | 31 | 40 |
| 4 | 400 | 41 | 50 |

SELECT * FROM tablename where ( which you want to find ) between min(columnName) and max(columnName);

Example:

SELECT * FROM shipment_charge where 25 between min and max;

Output:

+----+------+------+------+
| id | price | min | max |
+----+------+------+------+
| 2 | 200 | 21 | 30 |