Hi people,
I am trying to make my own auto_increment for some tables as the ID's
have a string prefix in front of them. For example:
- customer table has the prefix CUS,
- employee table has the prefix EMP,
- item table has different prefixes like WB, WC, TFB, etc...
The difficulty i am having is finding the last inserted row for that
table. When I use the following SQL statement I don't get what i would
expect since MAX() orders them as strings and not numbers.
SELECT MAX(ITEMID) FROM Item WHERE ITEMID LIKE "TFB%";
If i was to run this query on the Item table which has the following
ID's:
WB0, WB1, WB2,...TFB0, TFB1,...TFB100, TFB101
The result that i would get is: TBF99 where i should be getting TFB101
!
I have tried everything from BINARY casting, using ORDER BY to
SUBSTRING but they all order the same way.
I.E TFB0, TFB1, TFB100, TFB101, TFB2, TFB20, TFB21,...TFB99
Is there a quicker way to auto increment with a prefix in mysql or
not?
Thanks for ur help,
DoopZ