Tuesday, January 25, 2022

[FIXED] MYSQL Query to INSERT INTO a value into one row and copy data from another table into another row

Issue

I need something like this

INSERT INTO `tb1`(`button`,'name')
SELECT button FROM `tb2` WHERE `ID` = 1, VALUE ('some name')

In button I want to copy button data from tb2, In name I just want to put in a name. I can either copy from another table or enter a VALUE but I cannot do both.

Any suggestions would be appreciated.


Solution

Try this:

INSERT INTO `tb1`(`button`,`name`)
SELECT button, 'Some name' FROM `tb2` WHERE `ID` = 1


Answered By - Gurwinder Singh

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.