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

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

    Try:

    insert into tableX (a_id, b_id)
    SELECT service_id, 4 as QUESTIONMARK FROM tableY WHERE id in (10, 2);
    

    This works on many database engines however we don't know what environment you are working on.

    EDIT: What is the second insert supposed to be?

提交回复
热议问题