Answer the question
In order to leave comments, you need to log in
How to make a complex MySQL UPDATE query to partially merge data from two tables?
Good day!
Tell me how to correctly make a query to update data if there are 2 tables, each of which has user_id and unicnumber fields. You need to take a pair of table1.user_id->table1.unicnumber (1 to 1) from one table and copy the unicnumber value to all records of another table, where table1.user_id matches table2.user_id. It will turn out table2.user_id->table2.unicnumber (Many to one).
The query for getting from the first table is: SELECT user_id, unicnumber FROM table1 WHERE accept = 1;
An example of an update request to another table is: UPDATE table2 SET unicnumber = 1234 WHERE table2.user_id = 1;
It is possible to execute 100,000 requests in a PHP loop, forming them based on the data received from the first request. But maybe there is a more elegant solution using MySQL?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question