简体   繁体   中英

INSERT block of rows from a column from one table to another table

How do I insert a block of rows from a column from one table and insert that block at a certain place in another table? See screenshot

在此输入图像描述

So, what i need to do is to insert the block of missing data in "aktier" from aktie2. The "datum"-column between the tables must match exactly. So - is it possible to do this at once (without a loop) ?

I want to copy "aktie"-column (table aktie2) to aktie2-column (table aktier)

you can do this by update join query using concat function like this

update aktier 
join aktie2 on aktie2.id = aktier.uid
set aktier.aktie2 = concat (aktier.aktie2, aktie2.aktie )

Seeing your screenshot, it looks like you are looking for an UPDATE, not an INSERT:

update aktier
set aktie2 = (select aktie from aktie2 where aktie2.datum = aktier.datum)
where aktie2 is null;

In your scenerio it is an update case not an insert.

    URPDATE aktier
    SET aktie2 = (SELECT aktie FROM aktie2 where aktie2.id = aktier.id)
    where aktie2 is null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM