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!
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With