Get a DB result with a value between two columns values
Posted
by vitto
on Stack Overflow
See other posts from Stack Overflow
or by vitto
Published on 2010-06-15T11:07:35Z
Indexed on
2010/06/15
11:12 UTC
Read the original article
Hit count: 237
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
© Stack Overflow or respective owner