i have username in my database like abc,abc1,abc2,abc3. i want to retireve name abc3. my query is : select username from users where REGEXP '^abc[0-9]*$' order by userid limit 0,1.
in detail:- i have to fetch user whose name starts with abc and after that there must be only digits. and the one who have largest digit after abc i have to find that. i know largest userid will have largest digit after abc. so i have to find out all users with username strats with abc and after that contains digiits.
i have to apply this logic to make custom user names.for example if user firstname is ab and lastname is cat. then username will be abc. if abc exists in database then username will be abc1. if abc1 exists in database then username will be abc2.so on...
how to i rewrite my query to make it faster.