There is a table with 3 fields:

  1. a PK AI,
  2. b,
  3. c, The task is that in the table there are no records with the same fields b and c when interacting with it

INSERT INTO tbl (b, c) set b = 123, c = 123 ON DUPLICATE KEY UPDATE b = 123 AND elem_id = 123;

  • Is this a report of your exploits or did you just forget to write a question? who forbids you to make Unique to 2 fields? (b + c) - Vladimir Klykov
  • @Vladimir Klykov, the question is, how can I achieve this? I tried to do this by the above query, but alas, it did not work out ... - Clool Mear
  • Change the structure of the database. Add a unique key and stuff your b and c into it - Vladimir Klykov
  • one
    create unique index b_c_index on tbl(b, c) - Mike
  • one
    And so that the record is simply not inserted enough to write insert IGNORE into tbl(b,c) values(123, 123) (in the presence of a unique index, of course). And the clause on duplicate modifies the existing entry, if any. And watch the insert syntax carefully. you either write into tbl(b, c) values(...) or into tbl set b=123, c=123 and do not mix these two styles - Mike

0