SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict joyce's Avatar
    Join Date
    Aug 2001
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to write this sql query?

    how can i select a field from table a and insert into table b with other records?

  2. #2
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this should do it, just add column names as needed:

    PHP Code:
    <?php
    $sql 
    mysql_query("INSERT INTO table-a (field-a) SELECT field-a FROM table-a WHERE id='$id'") or die (mysql_error());
    ?>
    http://www.mysql.com/doc/I/N/INSERT_SELECT.html

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whoa.... u can run two queries at once?
    like
    "select * from table Insert into table values('a')"

  4. #4
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by slighltywhacked
    whoa.... u can run two queries at once?
    like
    "select * from table Insert into table values('a')"
    I do not think MySQL supports the SELECT .. INTO .. form. As far as I know INSERT INTO .. SELECT .. is the only form of 'nested' query in MySQL.


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
  •