Is it possible in MySQL to select rows for a certain range of items?
For example when I want to select all items in where the first letter of the NAME is between the B and T, alphabetically.
I know I can make this is PHP aswell, but it would save me a bit of time if this is possible in MySQL…
Is it possible, and if so, how?
The ideal situation would be something like this:
$sql="SELECT * FROM paths FROM name=name1 TO name=name6"; //which would select name1, 2, 3, 4, 5, 6.
Using
BETWEENwill basically get you there, but you need to use one letter past where you want to end. Experiment until you get the result you desire.The idea here is that everything beginning with a ‘T’ will sort alphabetically before anything beginning with a ‘U’. You need to convert it to upper-case via
UPPER()so you don’t run up against potential collation problems.So your results could be like:
But
Uwe(He’s German) would be excluded.