Skip to content Skip to sidebar Skip to footer

Mysql Insert Order Number By VARCHAR Field

I have a question about inserting row order number by spesific order type. Products table has OrderNumber field. I want to programaticly add new line to appropriate OrderNumber by

Solution 1:

You can use STRCMP('text', 'text2')

update products 
set OrderNumber=OrderNumber+1 
where STRCMP(Name, 'bla') = 1;

I missunderstood your point. Can you try something like this?

SET @rownum:=0;
update 
set OrderNumber=@rownum:=@rownum + 1
from products
order by Name;

Solution 2:

You can simply run an update query with a sequential number like in here


Solution 3:

Sounds like a bad design. Why not simply have a plain-jane auto_increment field and order by that? Every new record would by defnition have a higher ID than any of its predecessors.


Solution 4:

you mean something like update products set OrderNumber=OrderNumber+1 where Name like 'bla%'


Post a Comment for "Mysql Insert Order Number By VARCHAR Field"