A
A
Alexander2015-09-16 09:18:54
MySQL
Alexander, 2015-09-16 09:18:54

How to write SQl query for data recovery?

There are two tables, one backup is not the other.
355f500f292749d09f9b98044e2c2b9c.png
woodfun.toys_users has two fields company and inn where all records have the same data 6ba5f2cf31c44101bef68b181d071cc2.png.
And there is a backup from the day before yesterday. 6f48b61985e441e9a53668f2398c903f.png
You need to update all the data from the ghujgu table to the woodfun table where company=`SP Kolya1` and inn=`1234567891`.
I decided to make a SQL query:
UPDATE SET toys_users = ghujgu.toys_users WHERE `toys_users`.`company` = `IP Kolya1` AND ghujgu.`toys_users`.`inn` =`1234567891` .
Error :
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET toys_users = ghujgu.toys_users WHERE `toys_users`.`company` = `IP Kolya' at line 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
heartdevil, 2015-09-16
@kentuck1213

Hello.
To begin with, once again make a backup of all the tables included in the query)) so that if anything, it's not my fault.
And then try this query:

UPDATE woodfun.toys_users AS w, ghujgu.toys_users AS g
SET
w.email = g.email,
w.name1 = g.name1,
w.name2 = g.name2,
и так далее
w.discount = g.discount
WHERE w.id = g.id

Perhaps some fields will have to be quoted, in general, you will need to be smart with this request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question