How to update mysql column with another value from another table?

forum.test17

How to replace the value in 'projectId' column with project name assuming there is another table with name 'project' and two tables are related on the number mentioned after ':' in 'projectId' column of employee output.

> select * from employee;
+----+-----------+
| id | projectId |
+----+-----------+
|  1 | project:1 |
+----+-----------+

Desired output :

+----+-----------------------+
| id | projectId             |
+----+-----------------------+
|  1 | project:internProject |
+----+-----------------------+

Steps required:

extract the integer [done]

update employee SET projectId = substring_index(projectId,':', -1);

update the projectID with name [not sure :( ]

update employee SET projectId = concat('project:', select projectName from projects where projects.projectID = employee.projectId);
ebahi

You need parenthesis around your subrequest.

update employee e
set projectId = concat('project:',
                       (select projectName
                        from projects
                        where projectId = substring_index(e.projectId, ':', -1)));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to update mysql column with another value from another table?

From Dev

mysql update column value from another table

From Dev

Update column from another table column value

From Dev

Column loop and update another column with COUNT() value from another table

From Dev

mysql update an column from another table

From Dev

MySQL update column from another table

From Dev

How to Update Column from a Column in another table

From Dev

Update value in a column based on another column in the same table in MYSQL

From Dev

Update value in column based on column count in another table with mysql

From Dev

MySQL update column value with max value from another column

From Dev

Update column in one table based on value in another table in mysql

From Dev

Update column in one table based on value in another table in mysql

From Dev

MySQL - Update/Set a column in one table equal to MAX value from another table

From Dev

Mysql - update table column from another column based on order

From Dev

Update a particular column from another table column in mysql

From Dev

How to update table column's value from another table in sequence when table do not relate with each other

From Dev

update a column with derived value from another column in mysql

From Dev

update a column with derived value from another column in mysql

From Dev

Update MySQL datetime column with subtracted value from another row in same table

From Dev

Update value with days value from another table - mysql

From Dev

Update column with value from another table using SQLite?

From Dev

oracle update first 4 characters with column value from another table

From Dev

update column values by looking up value from another table

From Dev

Mysql - update column from another table data without reducing rows

From Dev

MySQL update column which is a value in another column

From Dev

MySQL update column which is a value in another column

From Dev

How can I update a column with same value in another table ssms?

From Dev

How to Replace and Update Data From One Table to Another Table in MySQL

From Dev

How to Replace and Update Data From One Table to Another Table in MySQL

Related Related

  1. 1

    How to update mysql column with another value from another table?

  2. 2

    mysql update column value from another table

  3. 3

    Update column from another table column value

  4. 4

    Column loop and update another column with COUNT() value from another table

  5. 5

    mysql update an column from another table

  6. 6

    MySQL update column from another table

  7. 7

    How to Update Column from a Column in another table

  8. 8

    Update value in a column based on another column in the same table in MYSQL

  9. 9

    Update value in column based on column count in another table with mysql

  10. 10

    MySQL update column value with max value from another column

  11. 11

    Update column in one table based on value in another table in mysql

  12. 12

    Update column in one table based on value in another table in mysql

  13. 13

    MySQL - Update/Set a column in one table equal to MAX value from another table

  14. 14

    Mysql - update table column from another column based on order

  15. 15

    Update a particular column from another table column in mysql

  16. 16

    How to update table column's value from another table in sequence when table do not relate with each other

  17. 17

    update a column with derived value from another column in mysql

  18. 18

    update a column with derived value from another column in mysql

  19. 19

    Update MySQL datetime column with subtracted value from another row in same table

  20. 20

    Update value with days value from another table - mysql

  21. 21

    Update column with value from another table using SQLite?

  22. 22

    oracle update first 4 characters with column value from another table

  23. 23

    update column values by looking up value from another table

  24. 24

    Mysql - update column from another table data without reducing rows

  25. 25

    MySQL update column which is a value in another column

  26. 26

    MySQL update column which is a value in another column

  27. 27

    How can I update a column with same value in another table ssms?

  28. 28

    How to Replace and Update Data From One Table to Another Table in MySQL

  29. 29

    How to Replace and Update Data From One Table to Another Table in MySQL

HotTag

Archive