Jhon Doe Photo

MARKO JAKIĆ

software engineer / web developer

Download vCard
  • Insert table column to another table column in SQL

    Posted by markzero on Sunday, November 20th, 2011

    If you have an empty new table, and wanted to transfer IDs from another table you could do this:

     
    INSERT INTO new_table (user_id) SELECT existing_table.ID FROM existing_table;

    If you would like to preserve order you can just order by any column from existing table:

     
    INSERT INTO new_table (user_id) SELECT existing_table.ID FROM existing_table ORDER BY existing_table.any_column;

    ;)

    Tweet

    Posted in: MySQL, SQL.

    Share this story:

    Share 'Insert table column to another table column in SQL' on Bebo Share 'Insert table column to another table column in SQL' on Blogger Share 'Insert table column to another table column in SQL' on Delicious Share 'Insert table column to another table column in SQL' on Digg Share 'Insert table column to another table column in SQL' on Fark Share 'Insert table column to another table column in SQL' on Google Bookmarks Share 'Insert table column to another table column in SQL' on LinkedIn Share 'Insert table column to another table column in SQL' on Mixx Share 'Insert table column to another table column in SQL' on Newsvine Share 'Insert table column to another table column in SQL' on reddit Share 'Insert table column to another table column in SQL' on Spurl Share 'Insert table column to another table column in SQL' on Squidoo Share 'Insert table column to another table column in SQL' on StumbleUpon Share 'Insert table column to another table column in SQL' on Yahoo! Buzz Share 'Insert table column to another table column in SQL' on Email

    Leave a Reply

    Click here to cancel reply.

    • Useful Links

      • Image Resizer Online Tool
      • Image Rotator Online Tool
      • MJ Posts Extras
      • MJ Quick Comments
      • MJSlider
      • Random Text Paste
    • Categories

      • CSS
      • DOM
      • Javascript
      • JQuery
      • Linux
      • Magento
      • MySQL
      • PEAR
      • PHP
      • PHPUnit
      • Prototype JS
      • Ruby
      • SQL
      • Tech
      • Ubuntu
      • Wordpress
      • XML
      • YouTube

    Archives

    • July 2012
    • June 2012
    • April 2012
    • December 2011
    • November 2011
    • October 2011
    • September 2011
  • HOME