开发者

Get a DB result with a value between two column values

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      example@example.com       http://example.com
pluto        33      example@example.com       http://example.com
mikey        78      example@example.com       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 *
F开发者_开发问答ROM 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


Select
  *
From
  table_profiles As profiles,
  table_users As users
Where
  users.age Between profiles.start_age_rage And profiles.stop_age_range


What about

    SELECT *
    FROM table_profiles AS profiles
    Where 
 users.age >= profiles.start_age_range AND users.age <=profiles.stop_age_range
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜