Reputation: 6789
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?
Upvotes: 0
Views: 88
Reputation: 43494
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:
select owner from info, (select 20 union select 30 union select 40) t2
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:
owner1 | 20
owner1 | 30
owner1 | 40
owner2 | 20
owner2 | 30
owner2 | 40
owner3 | 20
And so on. Is it clear?
Upvotes: 1