I am new to this, so I apologize in advance for any confusion / disappointment. I appreciate any help I can get!
I have a table ( MainTable ) in which I created two views using GoodTable and BadTable ).
- Each table has 4 columns (ID, UserID, key, value).
- An identifier is a primary key, but
- A user identifier can be repeated in several lines.
What I need to do in the Home table is to find the identifiers that are in the BAD table and update the values from the GOOD value column based on the UserID and LIKE matches with the key column in the MAIN table .
Hope this makes sense.
I tried:
UPDATE MainTable
SET value = (SELECT value FROM GoodTable
WHERE MainTable.UserID = GoodTable.UserID
AND MainTable.key LIKE "some%key%specifics");
This calls me ALMOST, but the problem is that if it does not find the specific features of LIKE, it returns NULL, and I want it to keep its original value if it is not in BadTable (BadTable is essentially all keys that comply with LIKE specifications). Obviously, the above does not use BadTable, but I thought it might help me solve this problem (not so, so far!) ...
Here is a little example:
MainTable:
ID UserID key value
1 1 key1 good value
2 1 key2 bad value
3 1 key3 unrelated value
4 2 key1 good value
5 2 key2 bad value
6 2 key3 unrelated value
GoodTable:
ID UserID key value
1 1 key1 good value
4 2 key1 good value
BadTable:
ID UserID key value
2 1 key2 bad value
5 2 key2 bad value
What I want MainTable to change to:
ID UserID key value
1 1 key1 good value
2 1 key2 good value
3 1 key3 unrelated value
4 2 key1 good value
5 2 key2 good value
6 2 key3 unrelated value
, - VLOOKUP (, Excel), , , , . , :)
, , , , MySQL...
, , , , !
UPDATE: @Rabbit, , ( , MainTable, MainTable , ..):
UPDATE MainTable
JOIN GoodTable ON MainTable.ID = GoodTable.ID
SET value = (SELECT value FROM GoodTable
WHERE MainTable.UserID = GoodTable.UserID
AND MainTable.key LIKE "some%key%specifics");
, , , , !
( , ) - . ! ( @DBug @Rabbit , !)