Home > front end >  Adding Information from Table to Another
Adding Information from Table to Another

Time:11-14

REPLACE INTO ytuser (id, yt1, yt2, yt3) SELECT DISTINCT userid, yt1, yt2, yt3 FROM ytid WHERE userid BETWEEN 1 AND 10000;

Hello, So i have made this SQL to convert information from a table to another tho after using this SQL it deleted the old information but it inserts what i need.. I want the query to only replace/update old yt1-yt2-yt3 according to id in ytuser which is userid in ytid.

CodePudding user response:

Update ytuser set 
ytuser.yt1=ytid.yt1,ytuser.yt2=ytid.yt2,ytuser.yt3= ytid.yt3
From ytuser 
inner join ytid 
on ytuser.id=ytid.userid
where ytid.userid between 1 to 10000;

CodePudding user response:

seems you need an aupdate and not an insert then in mysql you could try using update with join

    Update ytuser 
    inner join ytid on ytuser.id=ytid.userid
    set ytuser.yt1 =ytid.yt1
        ,ytuser.yt2 =ytid.yt2
        ,ytuser.yt3= ytid.yt3
    where ytid.userid between 1 to 10000;
  • Related