Using insert into … select results in a incorrect syntax near select, why?

后端 未结 6 1060
时光取名叫无心
时光取名叫无心 2021-02-05 02:46

How can I make a SELECT inside an INSERT operation?

insert into tableX (a_id, b_id) 
VALUES ((SELECT service_id 
         FROM tableY 
         WHERE id = 10, 2))         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 02:48

    you don't need the values word.

    here is some documentation for mysql

    http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

    also, when you specify the columns into which the values should be inserted, you need to make sure your select returns the same number/types appropriate to what you specified.

提交回复
热议问题