I would like to insert data in MySQL with automatic naming on field username but how i can do it?.
Currently data at table is:
+----+----------+ | id | username | +----+----------+ | 1 | admin1 | | 2 | admin2 | +----+----------+
I try using this sql but it's can't:
INSERT INTO `tbl_user` (
`username`
)
VALUES (
CONCAT('admin',(SELECT MAX(SUBSTRING_INDEX(`username`,'admin',-1))+1 FROM `tbl_user`))
);
and get error message #1093 - You can't specify target table 'tbl_user' for update in FROM clause
Final result i want is:
+----+----------+ | id | username | +----+----------+ | 1 | admin1 | | 2 | admin2 | | 6 | admin3 | | 9 | admin4 | +----+----------+
is that possible? thanks.
UPDATEto concatenate theidwithadmin.idbut MAX(SUBSTRING_INDEX(username,'admin',-1))+1. Is that possible?