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

  • 1
    a command that will sort by A-Z The sorting is performed by using ORDER BY clause in the query with proper sorting expression. In your case ORDER BY product_name is enough. – Akina Oct 18 at 7:35
  • @Akina see my edit, this is not what I'm struggling – Freedo Oct 18 at 7:48
UPDATE sourcetable
SET number_order = (@tmp := @tmp + 1)
WHERE NOT (@tmp := 0) 
ORDER BY products_name ASC


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.