skip to Main Content

I want to copy a row for example whith ID=23 in a table A into another table with ID=30 into another database. I got this

INSERT INTO pacaya_control_venta.tb_venta_pacaya WHERE ID=33
SELECT * FROM llamadas.tb_venta_pacaya WHERE ID = 48;

But I think the double WHERE is wrong. Any thoughts???

2

Answers


  1. Is this what you need?

    INSERT INTO pacaya_control_venta.tb_venta_pacaya (id, col1,col2,col3,col4,...)
      SELECT 33, col2, col3, col4,.... FROM llamadas.tb_venta_pacaya WHERE ID = 48;
    
    Login or Signup to reply.
  2. Assuming both the table contain the same columns (col1, col2, …) and the db are on the same server
    for copy a row you should use update .. not insert

    UPDATE pacaya_control_venta.tb_venta_pacaya  a
    INNER JOIN llamadas.tb_venta_pacaya  b ON a.id=33 and b.id = 48 
    SET a.col1 = b.col1,
        a.col2 = b.col2, 
        ..... 
    

    insert is for create a new row not for updated existing one

    INSERT INTO pacaya_control_venta.tb_venta_pacaya 
    SELECT * 
    FROM llamadas.tb_venta_pacaya 
    WHERE ID = 48;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search