-1

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??

andruw oei
  • 39
  • 5

1 Answers1

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