3

I have a user table like this:

User (id, name, rank)

I want to check user's rank and get the corresponding text (ex: if user's rank in between 1-10, I can get the text "User in top 10!")

I created a rank_text table like this:

rank_text(id, rank_from, rank_to, text)
         (1,  1,         10,      "You are in top 10!")

How I can query this case?

Can you give me a advise?

Thank you very much!

1 Answer 1

5

You can use a join:

select u.*, rt.text
from users u left join
     rank_text rt
     on u.rank between rt.rank_from and rt.rank_to;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.