Quantcast
Channel: MySQL
Viewing all articles
Browse latest Browse all 14

MySQL Updating a database table from another table

$
0
0
What?
A quick article on how to populate a database column from another table using a string comparison.

Why?
I have several database tables which replicate country names and I would rather they all use the ccTLD two letter code. This article was written because it took me so long to work it out.

How?
UPDATE  `table_to_update` a
        INNER JOIN `table_to_read` b
            ON a.`CountryName` COLLATE utf8_general_ci LIKE b.`CountryName` COLLATE utf8_general_ci
SET     a.`ccTLD` = b.`ccTLD` 

Viewing all articles
Browse latest Browse all 14

Trending Articles