Skip to content
Loading
  • +3
    Hi
      
         In think this will help you
         insert into TableA(id) select id from TableB where name='something'  
    +3
  • +3
    Hi Abhinandhu,
     
    For copying some column from one table to another table, use below query.
     
    INSERT INTO table2 (column1, column2, column3, ...)
    SELECT column1, column2, column3, ...
    FROM table1
    WHERE condition;
     
    For more reference follow below link
     
    https://www.w3schools.com/sql/sql_insert_into_select.asp
    +3
  • Chandresh Pansuriya
    +3
    Example : The following statement inserts all addresses from the customers table into the addresses table:
     INSERT INTO sales.addresses (street, city, state, zip_code)   
     
    1. INSERT INTO sales.addresses (street, city, state, zip_code)   
    2. SELECT  
    3.     street,  
    4.     city,  
    5.     state,  
    6.     zip_code  
    7. FROM  
    8.     sales.customers  
    9. ORDER BY  
    10.     first_name,  
    11.     last_name;   
     
    +3
  • Aman Gupta
    +2
    Use this Query - INSERT INTO table with value SELECT FROM another table.
     
    Explanation - You can use SELECT FROM statement to retrieve data from this table, then use an INSERT INTO to add that set of data into another table, and two statements will be nested in one single query.
     
    Hope this makes sense.
    +2