How do I compare two MySQL tables and then update one of them

ASquared

I have two tables called it_systems and departments. The it_systems table contains all the department names but I want to add in all their ID's so I can remove the deprtmentNames column. so I need to compare the name with the name in the department table and then insert the departments.id into the it_systems.departmentid but seems to be falling flat as MySQL is not that great. This is how far I have got

UPDATE 
it_system_additional INNER JOIN
(
    SELECT departmentName
    FROM it_system_additional
) departments ON departments.DepartmentName = it_system_additional.departmentName
SET it_system_additional.departmentid = departments.departmentId

but I keep getting this error [Err] 1054 - Unknown column 'departments.departmentId' in 'field list' even though I know that column does exist.

Any help will be greatly appreciated. Thanks in advance. Andrea

Mittal Patel

User below query to achieve this:

UPDATE it_system_additional AS i
INNER JOIN departments AS d ON i.DepartmentName = d.departmentName
SET i.departmentid = d.departmentId

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL - How do I compare values in common between two tables

From Dev

How to select two tables compare them and get a single column value in PHP Mysql

From Dev

How can I update two different tables in one query?

From Java

How would I compare two dates in a form and validate them? The second one shouldn't be before the first one

From Dev

How can I update two unrelated mysql tables with a php script?

From Dev

How do I update two tables in a single method?

From Dev

How to compare two very large tables in MySQL?

From Dev

How to compare two tables using PHP and MySQL

From Dev

How do I compare two different values of the same field in MySQL?

From Dev

How do I compare average runtime of two functions in MySQL?

From Dev

How do you compare two fields in Mongo while performing an operation on one of them?

From Dev

How Can I compare two tables?

From Dev

How do I get MySQL tables to update each other?

From Dev

How do I get sum of two different columns from two diffrent tables and group them

From Dev

mysql - How to perform joining of of two junctional tables in case where one of them has foreign key of another?

From Dev

how do i join two different tables in mysql

From Dev

How do I compare two values from two vectors and then update the vector values in C++?

From Dev

How do I require one field or another or (one of two others) but not all of them?

From Dev

Compare values in two tables and calculate the difference of them

From Dev

how to compare one field that is common in each object of an array in two files and do update the array as well

From Dev

Two linked NSTables by NSArrayControllers are not updating simultaneously, if I update one of them

From Dev

Compare two tables from MYSQL

From Dev

UIColor and CIColor how do they compare and what is the purpose of having two of them?

From Dev

How do I compare two arrays and remove multiple items from one array that do not match in both arrays?

From Dev

How do I compare two arrays and remove multiple items from one array that do not match in both arrays?

From Dev

How do I insert two values in mysql with just one select?

From Dev

How do I combine two nested MySQL queries into one View?

From Dev

how can i compare two values and rank them in excel

From Dev

How can I compare results from Observables and return one of them

Related Related

  1. 1

    MySQL - How do I compare values in common between two tables

  2. 2

    How to select two tables compare them and get a single column value in PHP Mysql

  3. 3

    How can I update two different tables in one query?

  4. 4

    How would I compare two dates in a form and validate them? The second one shouldn't be before the first one

  5. 5

    How can I update two unrelated mysql tables with a php script?

  6. 6

    How do I update two tables in a single method?

  7. 7

    How to compare two very large tables in MySQL?

  8. 8

    How to compare two tables using PHP and MySQL

  9. 9

    How do I compare two different values of the same field in MySQL?

  10. 10

    How do I compare average runtime of two functions in MySQL?

  11. 11

    How do you compare two fields in Mongo while performing an operation on one of them?

  12. 12

    How Can I compare two tables?

  13. 13

    How do I get MySQL tables to update each other?

  14. 14

    How do I get sum of two different columns from two diffrent tables and group them

  15. 15

    mysql - How to perform joining of of two junctional tables in case where one of them has foreign key of another?

  16. 16

    how do i join two different tables in mysql

  17. 17

    How do I compare two values from two vectors and then update the vector values in C++?

  18. 18

    How do I require one field or another or (one of two others) but not all of them?

  19. 19

    Compare values in two tables and calculate the difference of them

  20. 20

    how to compare one field that is common in each object of an array in two files and do update the array as well

  21. 21

    Two linked NSTables by NSArrayControllers are not updating simultaneously, if I update one of them

  22. 22

    Compare two tables from MYSQL

  23. 23

    UIColor and CIColor how do they compare and what is the purpose of having two of them?

  24. 24

    How do I compare two arrays and remove multiple items from one array that do not match in both arrays?

  25. 25

    How do I compare two arrays and remove multiple items from one array that do not match in both arrays?

  26. 26

    How do I insert two values in mysql with just one select?

  27. 27

    How do I combine two nested MySQL queries into one View?

  28. 28

    how can i compare two values and rank them in excel

  29. 29

    How can I compare results from Observables and return one of them

HotTag

Archive