Insert modified value of one field into new field in SQL
P粉790187507
P粉790187507 2024-03-20 10:17:38
0
2
417

My problem is that I know nothing about SQL queries, but need to do something that I think shouldn't be difficult. I've tried some of the recommended questions but I just can't really understand how to extrapolate it to my case, hope you can help me.

Basically what I need is to create some rows in the table and use Values ​​from other rows in the same table, I'd try to be very specific.


I have a table (vb_postmeta) with a lot of rows, some of them look like this:

meta_id post_id MetaKey 元value
1434 500 bpxl_videourl 1006hyOKoUM
1435 501 bpxl_videourl skjd9F008mN

What I need here is, for each row, create a new row like this:

meta_id post_id MetaKey 元value
automatic 500 csco_post_video_url https://www.youtube.com/watch?v=lOO6hyOKoUM
automatic 501 csco_post_video_url https://www.youtube.com/watch?v=skjd9F008mN

meta_id is the key and therefore should be automatically generated, while post_id should be the same and meta_value should also have the same value with the Youtube URL appended in front.

I really don’t know how difficult this is, but I hope it’s not too hard,

Thanks in advance for any help, been struggling with this.

P粉790187507
P粉790187507

reply all(2)
P粉696891871

Assuming your meta_id is AI (auto-increment) and using mySQL (minor modification of MSSQL), try:

INSERT INTO vb_postmeta (
SELECT null,
post_id,
'csco_post_video_url'
CONCAT('https://www.youtube.com/watch?v=',meta_value
FROM vb_postmeta)
P粉151720173

Based on the suggested answers, I ended up using this:

INSERT INTO vb_postmeta(
    SELECT
        NULL,
        post_id,
        'csco_post_video_url',
        CONCAT('https://www.youtube.com/watch?v=', meta_value)
    FROM
        vb_postmeta
    WHERE
        meta_key = 'bpxl_videourl'
)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template