SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Insert question

  1. #1
    eCommerce specialist hotnuts21's Avatar
    Join Date
    Apr 2002
    Location
    Aberystwyth, UK
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert question

    Im trying to insert some data into a table. Now all of this data already exists in another table with the same names, all except on column which is unique to the customers input.

    If I was just taking from the one table to the other I would use

    INSERT INTO table2 (fa, fb) SELECT fa, fb FROM table1;

    But imagine I have a column called Fc in table 2 but not in table1, the value I want to insert into Fc is '2' or whatever the user has inputted.

    Is there an easy way to do this?
    Search & Rescue Aberystwyth Lifeboat
    CSS Tutorials/Guides

    Sitepoint signatures are not visible to Search Engines More info

  2. #2
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you want to really just copy the table?
    Then empty a column?

    Play around with PhpMyAdmin, get it to copy a table then look at the sql command it used.
    Upgrading to Mysql 5? Auto-increment fields now strict
    use NULL
    Or zero or leave the field name out completely.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    INSERT 
      INTO table2 
         ( fa, fb, fc ) 
    SELECT fa, fb, 2 
      FROM table1
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    eCommerce specialist hotnuts21's Avatar
    Join Date
    Apr 2002
    Location
    Aberystwyth, UK
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked a treat thanks r937
    Search & Rescue Aberystwyth Lifeboat
    CSS Tutorials/Guides

    Sitepoint signatures are not visible to Search Engines More info


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •