I'm trying to update id's in a table where the corresponding unique id is currently stored in another table.
Currently, the table structure is something like this:
Table 1
id | name |
---|---|
1 | As |
2 | Bs |
3 | C's |
Table 2
id | name | pay |
---|---|---|
null | As | 100 |
null | Bs | 200 |
null | C's | 300 |
UPDATE table2 t2
JOIN table1 t1 ON t2.name = t1.name
SET t2.id = t1.id
When I update the id's in table 2 by joining the names using the query above As and Bs get the correct id's, but all fields like C's don't find a match and result in having null id fields like below.
Result
id | name | pay |
---|---|---|
1 | As | 100 |
2 | Bs | 200 |
null | C's | 300 |
Desired Result
id | name | pay |
---|---|---|
1 | As | 100 |
2 | Bs | 200 |
3 | C's | 300 |
Any way to get mySQL to correctly join names with apostrophes in them?
CodePudding user response:
Apostrophe types were inconsistent.
In the comments @ysth mentioned there were different characters that are sometimes used as apostrophes, so replacing them all with the standard (') fixed most of the issues.