How to implement such update in the SQL database?

Hello. There is such a structure:

ainc |id |price |dost |name |field1 |field2 |field3
1 |78 |232 |1 |qwer |jdfglh |value2 |rghtr
2 |26 |139 |0 |dfwq |hutrh |value2 |gr46g
3 |99 |656 |1 |efew |rhier |value2 |fgdfg
4 |85 |134 |1 |43fd |ergui |value2 |xzvfg
5 |59 |614 |0 |vcrw |hjfue |value2 |dgrhj

ainc - auto_increment
id - primary key

Napoleo base in such a request

INSERT INTO db (id,price,dost,name,field1,field2,field3) VALUES ('65','659', '1','qwery','dfsdd','burgers','zxcdf')
Due to the fact that the table has a PRIMARY KEY, records with NOT unique field ID in the database does not get Duplicate entry Error
But can I update some fields if the DB saw the double?

There is a request database, SQL sees that the request contains double - ie ID is already in the database, and UPDATES the row for example on the columns price and fild3 for duplicate rows (ID).

Thank you very much for your help in solving the problem.
June 26th 19 at 14:04
1 answer
June 26th 19 at 14:06
insert into t1(a, b, c)
select d, e, f from t2
on duplicate key update b = e, c = f;
Ie need two tables? Where will they be overwritten? The first time there is a comparison, and then recording the results, right? - lura2 commented on June 26th 19 at 14:09
: well, you can and the same table and selectit
There is the link there is a description of the tool - orrin_Hilpert commented on June 26th 19 at 14:12

Find more questions by tags SQLMySQL