I have a table where I want to add auto Incrementing Id which isn’t there. The rows aren’t sorted. I want to add ID column based on the lexicographical order of another column, As shown below:
CURRENT TABLE AFTER ADDING ID
CLASS | ITEM ID | CLASS | ITEM
------|------- ---|-------|-------
fruits| banana 1 | fruits| apple
------|-------- ---|-------|-------
tools | hammer 2 | fruits| banana
------|-------- ---|-------|-------
fruits| apple 3 | flura | banyan
------|-------- ---|-------|-------
flura | banyan 4 | tools | hammer
------|-------- ---|-------|-------
fauna | human 5 | fauna | human
2
Answers
My suggestion would be to use a programming language (Python is awesome for these kinds of use cases and I’ll use that in my answer). The steps required would be as follows: