There is a table with 3 fields:
- a PK AI,
- b,
- 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;
Source: https://ru.stackoverflow.com/questions/926211/
All Articles
create unique index b_c_index on tbl(b, c)- Mikeinsert 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 writeinto tbl(b, c) values(...)orinto tbl set b=123, c=123and do not mix these two styles - Mike