I am new to MySQL statements, so bear with me.
I am working with a single table that contains 3 columns. ID, value, and report ID.
What I am looking to do is update the 'value' to yes of id = 2 WHEN the value is 'yes' for id = 1, and at the same time matching the report id is matching between id 1 and id 2. Apologies if this doesn't make sense, please let me know if I need to clarify better.
Here are some queries I've attempted so far:
UPDATE table
SET value = CASE WHEN value = 'Yes' AND id = 1 AND report_id LIKE report_id
THEN 'Yes' ELSE value END
WHERE (id = 2 or id = 1);
UPDATE table
SET value = 'Yes'
WHERE (report_id = report_id
AND value = 'Yes')
AND id = 1
OR id = 2;
UPDATE table
SET value = IF(value = 'Yes' AND report_id LIKE report_id AND id = 1, 'Yes', '')
WHERE id = 2;
Example Table:
| id | value | report_id |
|---|---|---|
| 1 | yes | 1001 |
| 1 | no | 1002 |
| 1 | yes | 1003 |
| 2 | 1001 | |
| 2 | 1002 | |
| 3 | cat | 1001 |
| 5 | 1002 |
report_id LIKE report_idwill always be true -- everything is always like itself. What are you trying to do with that?report_idbetween two different rows, you need to join the table with itself.