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

后端 未结 6 1054
时光取名叫无心
时光取名叫无心 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 03:08

    You don't need the values key word and also you can add the default value 2 for b_id column in the select list instead of adding it after the SELECT statement

    Try this:

    INSERT INTO tableX (a_id, b_id) 
    SELECT service_id, 2 
      FROM tableY 
     WHERE id = 10
    

提交回复
热议问题