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.

Reference

Advertisement

One response to “Mysql: Remove Duplicate Values on Creating A New Table”

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: