Use case: pick the newest row whose version is still less than or equal to the current app version.
String compare bites you:
1 | select "5.1.3" > "5.1.24"; |
MySQL returns 1 (true) because it compares lexicographically — at the patch segment, 3 is greater than 2.
Stack Overflow has a solid thread on this:
compare version numbers in MySQL
Assume x.y.z (fixed number of segments).
Filter by version range
Pad each segment to N digits (e.g. 5), concatenate, then compare the packed string:
1 | -- latest row with version <= 12.0.2 |
Sort by version only
When every segment is numeric, order by each part as a number:
1 | SELECT Version |
Questions? Leave a comment below or email: newbvirgil@gmail.com![]()
