I have id table primary key using varchar (BG-1) , I check max of id to decide what next id, but when data reach BG-10, the table cant add more data, because my query read BG-9 as max not BG-10, how to fix it??
Asked
Active
Viewed 24 times
-1
-
Possible dublicate of: https://stackoverflow.com/questions/8557172/mysql-order-by-sorting-alphanumeric-correctly – Stanislav Ivanov Jan 27 '18 at 03:24
1 Answers
0
Suppose your primary key is a column named "id" you could cast the number part as an integer and eliminate the "BG-" part, like this:
SELECT MAX(CAST(SUBSTR(id,4) AS UNSIGNED)) FROM table

JBA
- 2,889
- 1
- 21
- 38