SQL Insert data from multiple tables in different database

后端 未结 1 980
梦如初夏
梦如初夏 2021-01-26 10:50

I have cat table in a2 database I want to insert into id, img columns from different tables with different database

INSERT INTO a2.cat (id, img) SELECT i

相关标签:
1条回答
  • 2021-01-26 11:27

    I think you need to look into using a JOIN for this:

    INSERT INTO a1.cat (id, img)
    SELECT p.id, pi.name
    FROM topshop_test.product p 
        JOIN topshop_test.product-images pi ON p.id = pi.productid
    

    This assumes the product-images table has a productid field that links to the product table.

    0 讨论(0)
提交回复
热议问题