Mind burning query for me.
I want to fetch the all record between two age condition. Any one please help me. My query is write below
SELECT tbl_trip.* FROM tbl_trip WHERE ((tbl_trip.minage >='15' AND tbl_trip.maxage <='15') OR (tbl_trip.maxage <= '28' AND tbl_trip.minage >='28'))
This query checks your given range between minage and maxage, and vice versa.
select * from tbl_trip where (((minage>=15 and minage<=22)or(maxage>=15 and maxage<=22)) or((15>=minage and 15<=maxage)or(22<=maxage and 22>=minage)))
This is also working, Please check it properly before you use:
select * from tbl_trip where ((minage>=12 and minage<=22)or(maxage>=12 and maxage<=22)) or((12>=minage and 22<=maxage))
Here is another way:
select * from tbl_trip Where GREATEST(GREATEST(minage,12)-LEAST(maxage,22),0)=0