Is it possible to insert from a list of values from within in mysql?
INSERT INTO changes(uid,typ)
SELECT owner,(SELECT * FROM(20,30,40)) lst
FROM info
To put it another way, can you make a list of values act like the result a sub query?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Actually, what you’re trying to do is sintactically and semantically incorrect 🙂 You’re trying to return 3 rows from a select and put them into the outer select which just accepts one single value (1 column x 1 row).
Besides there is no way for MySQL to know to which user correponds each number, right? Then, if you had a way to link a user in the inner select to the outer select then you would have two tables and you would join them.
Now if you are actually looking to join each owner to each of the numbers you’re looking for a cartesian product. And you can do it like this:
This way, we’re creating a dummy table with 3 records and each of those records we’re linking them to the owner, this would result in:
And so on. Is it clear?