0

Is there any quick way to add some data to a table without either a) merging / replacing the whole thing or b) having to do it one cell at a time ?

example: i have a table loaded now with the counties of Arizona. I would like to add a few columns of county-specific data in-place. I don't want to merge unless i can merge in-place.

the end result would be as if i exported the data, added columns to it (e.g. in google docs), and created a new table using that same data. This is the thing to be avoided.

3

Yep, you can do it with SQL. Let's say you have two tables containing rows of data. Both have a column called county_code which is shared. To write a column of data from table_2 into table_1 you would run the following SQL,

UPDATE table_1 SET some_new_column = 
  (SELECT 
     some_old_column 
   FROM table_2 
   WHERE 
     county_code = table_1.county_code 
   LIMIT 1)

You would have to create the column new_column in table_1 and give it the same type (date, string, numeric) as the some_old_column in table_2.

You can do this a column at a time to make sure you are doing it okay and then just drop columns from table_2 when you don't need them anymore

  • ahh, wasn't thinking about the tables being accessible to each other but clearly they are in the same db. i'll give this a shot tonight and come back to mark the question answered. – vaxhax Jan 27 '14 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.