Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    7

    Red face Unanswered: copying a row from a table to another

    Hi,
    I am new to this field. Here is my issue:
    I have a table named 'udat' with data and another named 'ddat' one with similar columns( column names and their type and size are same) and have to add an entire row from udat to ddat, I tried the following code- must sound crap to u:


    INSERT INTO ddat values
    (
    select * from udat where id='000' )

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    You don't need the "VALUES" nor the opening bracket:
    Code:
    INSERT INTO ddd (col1, col2, col3)
    SELECT col1, col2, col3 
    FROM udat
    WHERE id = '000'

  3. #3
    Join Date
    Jun 2009
    Posts
    7
    Thank you Shammat, you are my savior.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Please take note that shammat has explicitly listed the columns in both the insert list and select lists - you should always do this too or your code can fall over after even the most minor schema change.

    Be explicit with your coding, not lazy.

    SELECT * should never make it into production.
    George
    Home | Blog

Posting Permissions

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