0

I am trying to insert into table A where one of it's value need to be selected from table B. I used the below query.

INSERT INTO `TableA` (`TableACol1`,`TableACol2`) VALUES ( 4, SELECT `TableBcol1` FROM `TableB` WHERE FirstName="shasha" )

I don't know what's going wrong with this but facing this error.

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax

shashank
  • 327
  • 1
  • 4
  • 17

1 Answers1

2

Insert the "4" inside the select

INSERT INTO `TableA` (`TableACol1`,`TableACol2`)
SELECT 4, `TableBcol1` FROM `TableB` WHERE FirstName="shasha"

https://dev.mysql.com/doc/refman/8.0/en/insert-select.html

cf_en
  • 1,661
  • 1
  • 10
  • 18
Roy Bogado
  • 4,299
  • 1
  • 15
  • 31