Mariadb – Serialize a column based on sorting order

mariadb

I have a column number_order and products_name I'm struggling to build a command that will sort by A-Z so that respectively:

A = 1
B = 2
C = 3

I'm using MariaDB. To be clear I want to run a command that will set the number_order starting from 1 to X, based on the products_name so that a product called A would have number_order = 1

Best Answer

UPDATE sourcetable
SET number_order = (@tmp := @tmp + 1)
WHERE NOT (@tmp := 0) 
ORDER BY products_name ASC

fiddle