SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Israel
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    insert ... select....

    hi there,
    i need to copy an entire row of data and insert it into a new insert command....
    i was wondering since this
    insert into userdetails select (UserName,FirstName,LastName) from userdetails where CurrentStatus=0;
    is not possible (according to the manual) and i tried severay possible variations. now this is only a small example to show what i mean the record itself has 36 cols... at first i tought of doing a select (each field name... 36 alltogether) from userdetails where CurrentStatus=0 and then to do an insert according to the values i got from the select... but to do it for 36 different cols... is there any way to copy entir row into a new record?
    anyone?
    thnx in advance.
    You can't see your self in the mirror with your eyes closed!

  2. #2
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Newcastle, England
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to tell us what database you're using for a start . Something similar to that is possible with some databases; for example in SQL Server, a query like:

    insert into table_1 select field_1, field_2 from table_2 where field_3 = 'blah'

    will work just fine .

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Israel
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im using mysql...
    You can't see your self in the mirror with your eyes closed!

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2000
    Location
    Grand Rapids, MI
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work for you, it runs on sybase, but there's nothing thats sybase specific (I don't believe) :

    insert into Table1 (field1,field2,field3)
    (select field1,field2,field3 from
    table2 where field4 = "whatever")

    Just select the fields in the order that you specify on the insert and run it all together.

    Hope that helps,
    Mike

    [edit] Or you can use myphpadmin if you have that, just dump the data from the table and change a few values on the dump file (the new table name, for instance) and populate your new table with it...
    Last edited by mmccue; Mar 8, 2002 at 12:26.
    My new position : Target for Middle Management Hostility.


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
  •