1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Copying field from one column into another

Discussion in 'Databases' started by Baz@rr, May 4, 2006.

  1. #1
    Hi all, looking for some advice. I'm a complete database mong, so apologies if it's ludicrously simple or that.

    What I'm trying to do is copy across data from a table called uk_info to another table called idx_list.

    The field I want to copy from uk_info is called 'Postcode'. I want it to go into a field called 'postcode' in idx_list.

    This was what I tried first:

    INSERT INTO 'idx_list' ('postcode')
    SELECT 'Postcode' FROM 'uk_info'

    Which copied across the info okay. But...

    I wanted the postcode data to go into the idx_list table starting at record 1. Instead it added new records after all the existing ones. I have a list of business names in both tables, and want to add the postcode data from one table to the other. Both tables are currently ordered the same way by a numerical ID.

    So instead of now having business names plus corresponding postcode in idx_list, I have the business name records with a NULL postcode field, and then the postcode records with a NULL business name field. Not what I'm after at all.

    Apologies if this doesn't make much sense. I can clarify anything that's not already clear. Any help much appreciated.

    Baz
     
    Baz@rr, May 4, 2006 IP
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    UPDATE idx_list SET idx_list.postcode=uk_info.postcode WHERE idx_list.id=uk_info.id

    That would probably work as long both tables have the same ids.
     
    exam, May 4, 2006 IP