SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    moving row to new table with wildcards

    I need to move a row from one table to another table that shares the same structure. Is there a way to do that with wildcards?

    I thought something like this might work, but no go.

    PHP Code:
    mysql_query("INSERT INTO trkg_arc (*) SELECT * FROM trkg WHERE id = 3") or die(mysql_error()); 

  2. #2
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Maybe lose the (*) on INSERT:
    Code:
    INSERT INTO trkg_arc SELECT * FROM trkg WHERE id = 3

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks itmitică. That worked.

  4. #4
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    "Captain, the most elementary and valuable statement in science, the beginning of wisdom, is 'I do not know.'" - Lt. Commander Data, Star Trek TNG

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    San Sebastian, Spain
    Posts
    93
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It is better programming practice to both name the columns from the table being inserted and the table being selected. For example, let's imagine you add a new column to one table. Your code would all of a sudden stop working. Likewise if you rebuild your table and reorder the columns then you will get very strange results.


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
  •