Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to return all rows when given value lies between two columns

Tags:

sql

mysql

its easier selecting a row whose value is between given number. But I m having no luck to figure out this-

I have a table in which there are two fields min_age and max_age. How to return all rows when given value lies between min_age and max_age

P.S. I m still a newbie in sql, please forgive me if this sounds too silly.

Thanks

like image 332
Sharmila Avatar asked Jan 16 '23 07:01

Sharmila


2 Answers

SELECT *
FROM `tbl`
WHERE 35 BETWEEN `min_age` AND `max_age`;

That ought to do it. Of course, I used 35. You can use any other value instead.

like image 198
hjpotter92 Avatar answered May 07 '23 19:05

hjpotter92


You can use BETWEEN to get your desired result

 SELECT *
FROM tablename
WHERE <some value> BETWEEN `min_age` AND `max_age`;
like image 21
Rahul Tripathi Avatar answered May 07 '23 20:05

Rahul Tripathi