MySQL 插入多行 select 和一个常量值
MySQL insert multiple rows with select and one constant value
我想将两个值插入 table,一个值是常量 (user_id),第二个值是从另一个 table 中选择的。
我有一个错误:
#1064 - Something is wrong in your syntax obok 'select name from payment_methods_default)' w linii 1
insert into payment_methods_assigned_to_users (user_id, name)
VALUES (1, select name from payment_methods_default);
VALUES()
允许您只插入一行,而您想插入多行(在 payment_methods_default
table 中每行一行)。为此,请考虑 insert ... select
语法:
insert into payment_methods_assigned_to_users (user_id, name)
select 1, name from payment_methods_default
我想将两个值插入 table,一个值是常量 (user_id),第二个值是从另一个 table 中选择的。 我有一个错误:
#1064 - Something is wrong in your syntax obok 'select name from payment_methods_default)' w linii 1
insert into payment_methods_assigned_to_users (user_id, name)
VALUES (1, select name from payment_methods_default);
VALUES()
允许您只插入一行,而您想插入多行(在 payment_methods_default
table 中每行一行)。为此,请考虑 insert ... select
语法:
insert into payment_methods_assigned_to_users (user_id, name)
select 1, name from payment_methods_default