1

I would like to know if there is a way to use insert into...on duplicate key without use as parameter the primary key of the table, for example I have the following table :

+----+------------+------+--------+
| id | product_id | year |  name  |
+----+------------+------+--------+
|  1 |          5 | 2018 | Sword  |
|  2 |          7 | 2018 | Shield |
+----+------------+------+--------+

I have an array for insert in that database (PHP - PDO).

This array have 3 items :

  • the sword
  • the shield
  • and the potion

For example, with id as primary key, I would like to know if its possible to perform something like INSERT ... ON DUPLICATE KEY UPDATE instead using the id (because in this moment I'll not have the id)

I can use a where or something like that, cross the product_id and the year would be perfect.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

0 Answers0