0

i would like to insert two values into a table, one value is constant (user_id) and second values are selected from other table. I have an error:

#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);

1 Answer 1

5

VALUES() lets you insert just one row, while you want to insert multiple rows (one per row in the payment_methods_default table). For this, consider the insert ... select syntax:

insert into payment_methods_assigned_to_users (user_id, name) 
select 1, name from payment_methods_default
Sign up to request clarification or add additional context in comments.

1 Comment

What about multiple rows this way but the FROM table is a subquery?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.