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

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

    In MySQL one can insert dynamic values. Here is the sample:

    INSERT INTO Item_Info (`Back_Ground_Color`,) 
    VALUES ( (select concat('#',SUBSTRING((lpad(hex(round(rand() * 10000000)),6,0)),-6))));
    

提交回复
热议问题