Marketing digital. Making results.

Mysql: Remove Duplicate Values on Creating A New Table

I had a reference table for all of the World Countries that i wanted to extract Currency data from to another new table. I initially use this code which created a new table with 263 records.

CREATE TABLE currencies SELECT tld, currency, currencycode FROM countries ; 

I quickly realized that for the purpose I was creating this table, which is to have a unique list of currency codes, this didn’t work. The 263 rows were 99 too many as there are only 164 unique currency codes in my table. Dug around the net for a while and came up with this query:

CREATE TABLE currencies SELECT tld, currency, currencycode FROM countries GROUP BY currencycode; 

That took care of my initial problem.