Get a DB result with a value between two column values
- by vitto
Hi, I have a database situation where I'd like to get a user profile row by a user age range.
this is my db:
table_users
username age email url
pippo 15 [email protected] http://example.com
pluto 33 [email protected] http://example.com
mikey 78 [email protected] http://example.com
table_profiles
p_name start_age_range stop_age_range
young 10 29
adult 30 69
old 70 inf
I use MySQL and PHP but I don't know if there is some specific tacnique to do this and of course if it's possible.
# so something like:
SELECT *
FROM table_profiles AS profiles
INNER JOIN table_users AS users
# can I do something like this?
ON users.age IS BETWEEN profiles.start_age_range AND profiles.stop_age_range