Reputation: 359
I have a value of 15.
I then have a database which contains different ranks for the player.
They have the following information in my ranks table:
Level CountFrom CountTo
Level 1 0 9
Level 2 10 19
Level 3 20 29
How can i pull the level out in a sql command?
I.e i have:
SELECT *
FROM `ranks
WHERE `CountTo` <= '15'
This will pull Level 1 and Level 2 as result.
The only way i can think of is to then OrderBy CountTo DESC and limit the result to 1.
Is there a better way?
Upvotes: 0
Views: 2127
Reputation: 1449
You can use BETWEEN
SELECT *
FROM `ranks
WHERE '15' between `CountTFrom` and `CountTo`
Upvotes: 2
Reputation: 20494
You can use CountFrom
in the query as well.
SELECT *
FROM ranks
WHERE CountFrom <= 15 AND CountTo >= 15
CountTo
(9) value makes CountTo >= 15
false.CountFrom
(10) is true for CountFrom <= 15
and its CountTo
(19) is true for CountTo >= 15
.CountFrom
(20) values makes CountFrom <= 15
false.Upvotes: 4