I have a table, called Level.
id | level | points(minimum)
-------------------------
1 | 1 | 0
2 | 2 | 100
3 | 3 | 200
Let say I have 189 points, how do i check which level the user in?
EDIT:
Best answer chosen. Now I am comparing the request by adding EXPLAIN before the SELECT query, i have this result:
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
-------------------------------------------------------------------------------------------------------------
1 | SIMPLE | level | ALL | NULL | NULL | NULL | NULL | 8 | Using where
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
-------------------------------------------------------------------------------------------------------------
1 | SIMPLE | level | ALL | NULL | NULL | NULL | NULL | 8 | Using where; Using filesort
How do i know which one is better or faster?
If you’re looking for the level that the player is currently in, you want to select the maximum level with a points requirement less than the points the player currently has:
This may work better if each level has a
min_pointsandmax_pointsamount:Then your query wouldn’t need to aggregate:
Edit: ugh, I keep messing up my SQL tonight, LOL.