Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

MySQL create table containing values from a column in another table.

0

114 views

Lets say I have a table tilistings with a dozen columns, and about 2,000 rows there is one column cityname that has probably 50 different values in it. What I want to do, is search through the tilistings and create another table that just contains the 50 different values from cityname without duplicating any names....basically if cityname had the values a,b,a,c,b,b,d,a,a,d,d,c I would only want the new table to contain a,b,c. Is there a pre-built MySQL function to do so? Otherwise, just point me in the right direction to do this with PHP. I can create the table, just looking to populate it.

asked January 28, 2011 5:58 pm CST
posted via StackOverflow

1 Answer

1
Best answer
 

You can get the unique city names by performing the following query:

SELECT DISTINCT cityname FROM tilistings

Then loop through those and INSERT them into your new table with PHP or INSERT INTO ... SELECT.

answered January 28, 2011 6:23 pm CST

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions