F
F
Fullerent952019-07-04 19:43:41
MySQL
Fullerent95, 2019-07-04 19:43:41

How not to add the same values ​​to the database + check one field?

Good afternoon!
There is a request:

insert into test1 (case_id, component_number, component_name, test_type, test_name, test_description, cft, bisquit, cif, cifle)
values ('1', '018', 'nam_comp', 'pos', 't_01', 'тут текст', '1', 'false', 'false', 'false')
ON CONFLICT (case_id) DO update set
test_description='--новый текст--';

5d1e2d005e2c0727206528.png
Need advice on how to remake the table or rewrite the query so that:
1. when adding new records, the same records are not added
2. if the test_description in the new record has been changed, you need to change it in the old record

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2019-07-05
@fwervbyberstvrstrf

1. when adding new records, the same records were not added

Compare the new record, and find the old one by it. If there is no old one, then add it; if there is, then do not add it.
I didn’t quite understand what it was about, but if I understood it, then also check the test_description of the new record and the test_description of the old record. If the text is different, then replace the test_description of the old entry with the test_description of the new entry.
Something like this.

I
Immortal_pony, 2019-07-06
@Immortal_pony

INSERT ... ON DUPLICATE KEY UPDATE for mysql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question