SQL INSERT INTO with subquery and value

后端 未结 2 458
梦毁少年i
梦毁少年i 2020-12-16 13:09

Is there a way I can use a combination of hard values and a subquery to insert into a table with one command?

For example:

INSERT INTO suppliers (su         


        
相关标签:
2条回答
  • 2020-12-16 14:01

    Even simpler, just fill in the field with the value, dont even need an AS:

    INSERT INTO suppliers (supplier_id, supplier_name, supplier_type)
    SELECT account_no, name, 3
    FROM customers
    WHERE city = 'San Diego';
    
    0 讨论(0)
  • 2020-12-16 14:05

    Just add it with your SELECT fields.

    INSERT INTO suppliers (supplier_id, supplier_name, supplier_type)
    SELECT account_no, name, 3 AS supplier_type
    FROM customers
    WHERE city = 'San Diego';
    
    0 讨论(0)
提交回复
热议问题