I want to fill the password in user table by concatenating 4 char from user name and last 5 digits from the accountnumber in Employee table(another table)
I tried the below query,but it returns empty.
SET SQL_SAFE_UPDATES=0;
UPDATE user set password = (SELECT (CONCAT(SUBSTRING(user.username,1,4), SUBSTRING(employee.accountnumber,-5))) FROM employee WHERE user.employeename= employee.employeename);
SET SQL_SAFE_UPDATES=1;
When i tried SELECT statement seperately in editor,it returns exact values.
SELECT (CONCAT(SUBSTRING(user.username,1,4), SUBSTRING(employee.accountnumber,-5))) as pwd
FROM employee ,user WHERE user.employeename= employee.employeename;
xxxx03332
yyyy07674
But in UPDATE statement it is not working,as im setting password column as 'NOT NULL' option.when i execute in editor it shows error as Error Code: 1048. Column 'password' cannot be null I tried below query,but same error
UPDATE user password , (SELECT (CONCAT(SUBSTRING(user.username,1,4), SUBSTRING(employee.accountnumber,-5))) FROM employee WHERE user.employeename= employee.employeename);
If i include 'user'(table name) in FROM clause,it shows error as Error Code: 1093. You can't specify target table 'user' for update in FROM clause So, i deleted that in UPDATE Statement.