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.

Moving around fields in a Table

Discussion in 'MySQL' started by SEbasic, Nov 4, 2005.

  1. #1
    Ok, so I have 2 tables in a mySQL DB.

    The format for the first is this.

     tutorialid  	int(10) 
     title  	varchar(250) 
     description  	varchar(250) 
     date  	varchar(250) 
     ID1  	int(10) 
     sitename  	varchar(250) 
     URL  	varchar(250) 
     ID2  	int(10) 
     image  	varchar(250) 
    Code (markup):

    And for the second is

     site_id   	int(11)  
     url  	varchar(255) 
     title  	varchar(255) 
     short_desc  	text 
     indexdate  	date 
     spider_depth  	int(11) 
     required  	text 
     disallowed  	text 
     can_leave_domain  	tinyint(1)
    Code (markup):
    Now, what I need to know, is how can I get the info from the second DB into the first...

    Is there a bt of code that's like...

    SELECT 'site_id' FROM 'table2' INSERT into 'URL' in 'Table1'

    Know what I mean?

    I've been playing with this for a while and just can't do it. :|

    What would be even better would be if I could get all the info transferred in one go...

    Is that possible?

    Cheers

    Oliver
     
    SEbasic, Nov 4, 2005 IP
  2. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It's the other way around:

    insert into table1 (col11, col12) select col21, col22 from table2

    Just make sure that the number of columns in the select and their position matches columns in the insert. Back up you data before doing giving this a try.

    J.D.
     
    J.D., Nov 5, 2005 IP
    SEbasic likes this.
  3. SEbasic

    SEbasic Peon

    Messages:
    6,317
    Likes Received:
    318
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wow awesome - thanks very much - that made complete sense... Now it works.

    My problem I guess was that I was going at it from completly the wrong side - no wonder the statements were confusing me ;)

    Cheers
     
    SEbasic, Nov 7, 2005 IP
  4. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Tagging this one for my own future reference, thanks J. D.

    VG
     
    vectorgraphx, Nov 9, 2005 IP